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

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

WBOY
Release: 2016-06-13 12:04:44
Original
1099 people have browsed it

我想在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;
Copy after login


------解决方案--------------------
= <<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 />
Copy after login


參考: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 />
Copy after login

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template