I want to create a table in the SQL statement based on user input parameters in php. for example, I now use $ _ GET ['tablename'] to obtain the user input value, I want to create a table named $ _ GET ['tablename'] with an SQL statement in the PHP file. could you please refer to create & nbsp; table & nbsp; [tablename] How does tablename represent it? This SQL statement is correct. I use & nb. I want to create a table in the SQL statement in php based on user input parameters.
For example, if I use $ _ GET ['tablename'] to enter user input values, I want to create a table named $ _ GET ['tablename'] using an SQL statement in the PHP file, excuse me
Create table [tablename] How does tablename represent it? This SQL statement is correct.
I cannot use create table {. $ _ GET ['tablename?
------ Solution --------------------
$sql = <<
create table {$_GET['tablename']}
...
SQL;
------ Solution --------------------
= < Heredoc syntax: <. Provide an identifier after this operator, and then wrap the line. The next step is the string itself. Finally, use the identifier defined above as the end mark.
$content = <<
test
blog
FDIPZONE;
echo $content;
?>
Exam: http://blog.csdn.net/fdipzone/article/details/24937669
------ Solution --------------------
In this case, you can.
$sql =<<
CREATE TABLE `{$_GET['tablename']}` (
`id` int(10) unsigned NOT NULL auto_increment,
`name` varchar(100) NOT NULL,
`age` tinyint(4) unsigned NOT NULL,
`addtime` datetime NOT NULL,
PRIMARY KEY (`id`)
)
SQL;
mysql_query($sql) or die(mysql_error());