Vote count:
0
I want it so that every single time a new person registers on my site it creates a new table specifically for them. This is for a file system i am implementing. However, when trying to use a variable as the name of the table. It seems to give me a error. I was wondering if anyone knew why.
The following code is my create table code, I have already connected and selected a database earlier in the script so that is not the issue
$newuser = $_POST['username'];
$create = "CREATE TABLE".$newuser." (
column_one varchar (20) NOT NULL,
column_two int NOT NULL auto_increment PRIMARY KEY,
column_three int NOT NULL,
column_four varchar (15) NOT NULL,
column_five year
)";
$results = mysql_query($create) or die (mysql_error());
I then get the 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 'TABLEAdministrator9 ( column_one varchar (20) NOT NULL, column' at line 1
However, when just naming it something like "potato" it will go ahead and create it. So I am wondering if it is an issue to the syntax i am using when wanting it to use the resultant from the variable $newuser.
I am brand new to back end programming.
Thanks
asked 10 mins ago
1 Answer
Vote count:
1
You are missing a space:
$create = "CREATE TABLE ".$newuser." (
-----------------------^
column_one varchar (20) NOT NULL,
column_two int NOT NULL auto_increment PRIMARY KEY,
column_three int NOT NULL,
column_four varchar (15) NOT NULL,
column_five year
)";
answered 5 mins ago
Create new table with the name as a resultant from a variable is failing
Aucun commentaire:
Enregistrer un commentaire