Creating table with variable name php mysql

你说的曾经没有我的故事 提交于 2019-12-14 03:27:16

问题


I'am trying to create table with variable name and columns via forms here's my query

$execute =  mysql_query('CREATE TABLE '.$tName.'(
            '.$cName.' '.$cType.' )');

And it's creating table with name from variable $tName but it doesnt create the columns.


回答1:


Try this:

$sql= "CREATE TABLE $tName($cName $cType(45),$cName $cType(50))";

//echo $sql;
$op =mysql_query($sql);



回答2:


OK try this, I think it gives the general idea

<?php
include 'connect-db.php';
$tbl_name='kerry';
$field1='name';
$field2='value';
$field3='date';
mysql_query("CREATE TABLE `{$tbl_name}`
(
$field1 varchar(15),
$field2 int,
$field3 date
)");
?>


来源:https://stackoverflow.com/questions/29634469/creating-table-with-variable-name-php-mysql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!