I know that this has been asked hundreds of times before, but I looked around the Internet and couldn't find what could possibly be wrong with my syntax:
mysql_select_db('Projects');
$sql = "CREATE TABLE $data[ID] (
ID INT NOT NULL,
Creator INT NOT NULL,
Name VARCHAR(20) NOT NULL,
Version VARCHAR(20) NOT NULL,
Status VARCHAR(20) NOT NULL,
Date VARCHAR(20) NOT NULL,
Skript VARCHAR(20) NOT NULL,
Filename VARCHAR(20) NOT NULL,
Downloads INT NOT NULL,
PRIMARY KEY(ID)
)";
if (mysql_query($sql)){
echo "Created";
}else{
echo "Not created, ".mysql_error();
}
I tried using backticks, quotation marks et.c but in vain. The table name (21) displayed in the error is correct.
Here's the error that I get, including the echo "Not created, ";:
Not created, 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 '23 ( ID INT NOT NULL, Creator INT NOT NULL, Name VARCHAR(20) NOT NUL' at line 1
Rules for naming objects, including tables in MySql:
http://dev.mysql.com/doc/refman/5.1/en/identifiers.html
Identifiers may begin with a digit but unless quoted may not consist solely of digits.
you cant name your table start with digits
this will work forexample
$sql = "CREATE TABLE 't'.$data[ID] (
ID INT NOT NULL,
Creator INT NOT NULL,
Name VARCHAR(20) NOT NULL,
Version VARCHAR(20) NOT NULL,
Status VARCHAR(20) NOT NULL,
Date VARCHAR(20) NOT NULL,
Skript VARCHAR(20) NOT NULL,
Filename VARCHAR(20) NOT NULL,
Downloads INT NOT NULL,
PRIMARY KEY(ID)
)";
as you see it starts by t
or use backticks around it. like that
`$data[ID]`