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
    Regular Coder
    Join Date
    May 2007
    Posts
    130
    Thanks
    9
    Thanked 0 Times in 0 Posts

    MySQL syntax error???

    Hey Hey,

    having quite a bit of trouble with some code.

    Its all set up correctly, and should work, but i keep getting a syntax error.

    heres the code in question:

    PHP Code:
    if ($cmd=="commentpost")
    {

    $SCREEN_ID $sid;
    $MY_ID $_SESSION['user_id'];
    $BODY $_POST['comment'];
    $cur_date time();

    $BODY addslashes(nl2br($BODY));

    $sql mysql_query("INSERT INTO `screenshot_comments` (screen_id, user_id, timestamp, body, read) VALUES ('$SCREEN_ID','$MY_ID','$cur_date','$BODY','0')") or die(mysql_error());
                    
    $comment_posted true;

    the error i get is:

    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 'read) VALUES ('57','3','1210842919',abcde' at line 1

    ive checked and double checked my database and all the columns are named correctly etc.

    Any ideas?

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    READ is mysql reserved keword, I think ,see http://dev.mysql.com/doc/refman/5.1/en/handler.html

    So changing it like `read` may solve the issue. But usage of mysql keywords for naming tables/fields is not a good 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
    Regular Coder
    Join Date
    May 2007
    Posts
    130
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by abduraooft View Post
    READ is mysql reserved keword, I think ,see http://dev.mysql.com/doc/refman/5.1/en/handler.html

    So changing it like `read` may solve the issue. But usage of mysql keywords for naming tables/fields is not a good practice.
    Ah ok then, ill change it and try again.

    Confused me a bit because i already have 3 other tables with 'read' as one of the collumn and that gave me no errors.


  •  

    Posting Permissions

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