Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Feb 2010
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Little help needed...

    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:

    PHP Code:
    $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.

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,853
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    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/...ved-words.html

    You could use backticks around it, like `when`, but naming filed/table with keywords is a bad practice.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    New to the CF scene
    Join Date
    Feb 2010
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by abduraooft View Post
    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/...ved-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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •