views:

90

answers:

4

New to SQL. I'm looking to create a IT asset database. Here is one of the tables created with php:

mysql_query("CREATE TABLE software(
id VARCHAR(30), 
PRIMARY KEY(id),
software VARCHAR(30),
key VARCHAR(30))")
or die(mysql_error());  
echo "Software Table Created.</br />";

This is the output from the browser when I run the script:

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 'VARCHAR(30))' at line 5

I am running a standard LAMP stack on Ubuntu Server 10.04.

Thank you.

+7  A: 

key is a reserved word. If you really need this name, you should use quotes :

... `key` varchar(30)
a1ex07
Thank you for the quick reply. Appreciate it.
CT
+1  A: 

KEY is a reserved word in MySQL. Trying picking a different name for that field, or enclose it in backtick characters.

LesterDove
+1  A: 

try sw_key instead of key. Maybe key is a reserved word.

Larry K
+1  A: 

I would also change the lines

id VARCHAR(30),
PRIMARY KEY(id),

To

id VARCHAR(30) PRIMARY KEY,

to make the syntax more standard

KarateCowboy