#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2006
    Posts
    122
    Rep Power
    9

    Mysql insert syntax error


    Anybody see a syntas erro here: im currently debuging with xampp using PHP Server version: 5.1.41

    Code:
    mysql_query("INSERT INTO userimages(userid,imageid,url,views,likes,name,desc) VALUES ('$session_id','$count_checkimages','/user/$session_id/$file','0','0','$file','description here')") or die(mysql_error());
    i keep getting

    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 'desc) VALUES ('1','1','/user/1/image.jpg','0','0','image.jpg','descr' at line 1

    which is wierd because i copied this insert query changed the variables to suit the query. It works find for my registration page. i just added the die statment to the above code to see where the errors are comming from.


    This is from my registration page THIS WORKS!! Top one doesn't..
    Code:
    $query4 = mysql_query("INSERT INTO members(username,firstname,lastname,email,password,ip_address,last_logged_in,about,acctype,refcode,refby) VALUES ('$username','$fname','$lname','$email','$pass1','$ip_address',now(),'','$accountType','$refcode','$refby')") or die("Could not insert data.");
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    10
    Rep Power
    0
    I am far from an expert on this as I am learning as well. However in my queries I do not place integers between two '.

    I also would look into if you need to escape certain characters like the /.
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2006
    Posts
    122
    Rep Power
    9
    Originally Posted by Storm2012
    I am far from an expert on this as I am learning as well. However in my queries I do not place integers between two '.

    I also would look into if you need to escape certain characters like the /.
    oh yes i forgot about mysql_escape_string ill give it a try
  6. #4
  7. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Hi,

    you must not use "desc" as a column name, because it's a reserved word. The only way to get around this is by always wrapping the name in backticks ``.
  8. #5
  9. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2006
    Posts
    122
    Rep Power
    9
    ahhh thta would make sense because as soon i mess with the 's 'desc' turns in to 'des' within the error thx

    Originally Posted by Jacques1
    Hi,

    you must not use "desc" as a column name, because it's a reserved word. The only way to get around this is by always wrapping the name in backticks ``.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Posts
    33
    Rep Power
    3
    Correct

    PHP Code:
    mysql_query("INSERT INTO `userimages`(`userid`,`imageid`,`url`,`views`,`likes`,`name`,`desc`) VALUES ('$session_id','$count_checkimages','/user/$session_id/$file','0','0','$file','description here')") or die(mysql_error()); 
    never die your mysql_error on live server , very insecure
  12. #7
  13. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2006
    Posts
    122
    Rep Power
    9
    got it working thx a lot

IMN logo majestic logo threadwatch logo seochat tools logo