Home >Backend Development >PHP Tutorial >小弟我想在php中根据用户输入的参数在sql语句中建立表格

小弟我想在php中根据用户输入的参数在sql语句中建立表格

WBOY
WBOYOriginal
2016-06-13 12:04:441078browse

我想在php中根据用户输入的参数在sql语句中建立表格
比如我现在用$_GET[‘tablename’]来了用户的输入值,我想在php文件中用sql语句create一个名字叫$_GET[‘tablename’]的表格,请问
create table [tablename]这里的tablename如何表示呢这句sql语句才是正确的
我用 create table {. $_GET[‘tablename’]. }不能实现啊?
------解决方案--------------------

$sql = <<<SQL<br />create table {$_GET['tablename']}<br />...<br />SQL;


------解决方案--------------------
= heredoc 句法结构:

<br /><?php  <br />$content = <<<FDIPZONE  <br /><html>  <br /><head>  <br /><title>test</title>  <br /></head>  <br /><body>  <br /><p><img  src="http://www.csdn.net/css/logo.png" alt="小弟我想在php中根据用户输入的参数在sql语句中建立表格" ></p>  <br /><p><a href='http://blog.csdn.net/fdipzone'>blog</a></p>  <br /></body>  <br /></html>  <br />FDIPZONE;  <br />  <br />echo $content;  <br />?>  <br />


參考:http://blog.csdn.net/fdipzone/article/details/24937669
------解决方案--------------------
這樣就可以了。

<br />$sql =<<<SQL<br />CREATE TABLE `{$_GET['tablename']}` (<br />  `id` int(10) unsigned NOT NULL auto_increment,<br />  `name` varchar(100) NOT NULL,<br />  `age` tinyint(4) unsigned NOT NULL,<br />  `addtime` datetime NOT NULL,<br />  PRIMARY KEY  (`id`)<br />)<br />SQL;<br /><br />mysql_query($sql) or die(mysql_error());<br />

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn