-2

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.

Patryk Brejdak
  • 1,503
  • 14
  • 25

2 Answers2

0

Try this:

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

//echo $sql;
$op =mysql_query($sql);
akr
  • 739
  • 4
  • 15
0

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
)");
?>
kerry
  • 629
  • 1
  • 5
  • 9