I want to create a table in the SQL statement based on user input parameters in php.

Source: Internet
Author: User
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());

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.