daveh33 Posted January 4, 2008 Share Posted January 4, 2008 Trying to create a mysql table - I have the below code so far: - $name = $_POST['name']; $newtablename = "$name_numbers"; $query1="CREATE TABLE $newtablename (number varchar(11) NOT NULL)"; $result = mysql_query($query1) or die(mysql_error()); What I am trying to do - is use the POST data to create a table E.G Orange_numbers - There is only 1 field required in the table, called number I just get the below error: - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(number varchar(11) NOT NULL)' at line 1 Link to comment https://forums.phpfreaks.com/topic/84454-solved-create-mysql-table-in-php/ Share on other sites More sharing options...
Ken2k7 Posted January 4, 2008 Share Posted January 4, 2008 $newtablename = "$name_numbers"; What's $name_numbers? That variable isn't defined. Link to comment https://forums.phpfreaks.com/topic/84454-solved-create-mysql-table-in-php/#findComment-430232 Share on other sites More sharing options...
daveh33 Posted January 4, 2008 Author Share Posted January 4, 2008 I have the variable $name defined, I want it to use that input and add "_numbers" e.g create table name: test_numbers Link to comment https://forums.phpfreaks.com/topic/84454-solved-create-mysql-table-in-php/#findComment-430234 Share on other sites More sharing options...
Ken2k7 Posted January 4, 2008 Share Posted January 4, 2008 Try this: $name = $_POST['name']; $newtablename = $name."_numbers"; $query1="CREATE TABLE $newtablename (number varchar(11) NOT NULL)"; $result = mysql_query($query1) or die(mysql_error()); If you just say $name_numbers, that's the whole variable. Link to comment https://forums.phpfreaks.com/topic/84454-solved-create-mysql-table-in-php/#findComment-430240 Share on other sites More sharing options...
daveh33 Posted January 4, 2008 Author Share Posted January 4, 2008 Works perfectly - many thank Ken! Link to comment https://forums.phpfreaks.com/topic/84454-solved-create-mysql-table-in-php/#findComment-430243 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.