...

View Full Version : Little help needed...



bottyz
03-02-2010, 10:22 AM
Hi all,


Could anyone see why my sql query is throwing up this 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 'when, status) VALUES (NULL, 'cj', 'software', 'CJ_Pro_Software_Version_4_1_-_25_' at line 1

The query is:



$insert = "INSERT INTO downloadlogs (id, category, subcategory, file, username, referer, remoteaddress, when, status) VALUES (NULL, '$category', '$subcategory', '$filename', '$who', '$referer', '$address', '$serverdate', '$status')";

$add_userlog = mysql_query($insert) or die(mysql_error());


And if i echo it out is looks like:

INSERT INTO downloadlogs (id, category, subcategory, file, username, referer, remoteaddress, when, status) VALUES (NULL, 'cj', 'software', 'CJ_Pro_Software_Version_4_1_-_25_digit_license.zip', 'user12', 'http://www.bottyz.co.uk/LHU/cjsoftware.php', '217.39.143.37', '02 Mar 2010 09:18:23 am', 'Granted')

I've looked and looked for syntax errors for ages and even re-written the query and its now driving me bonkers. Any help would be much appreciated.

abduraooft
03-02-2010, 10:42 AM
Yes. WHEN is a reserved keyword of mysql, so you can't use them in queris as such as the name of a field/table. See http://dev.mysql.com/doc/refman/5.1/en/reserved-words.html

You could use backticks around it, like `when`, but naming filed/table with keywords is a bad practice.

bottyz
03-02-2010, 11:01 AM
Yes. WHEN is a reserved keyword of mysql, so you can't use them in queris as such as the name of a field/table. See http://dev.mysql.com/doc/refman/5.1/en/reserved-words.html

You could use backticks around it, like `when`, but naming filed/table with keywords is a bad practice.

Thanks a lot, your a life saver. I didn't think i was going potty.

I had no idea when was a keyword so i'll be avoiding it from now on.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum