November 18th, 2012, 06:03 PM
Mysql insert syntax error
Anybody see a syntas erro here: im currently debuging with xampp using PHP Server version: 5.1.41
i keep getting
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());
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..
$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.");
November 18th, 2012, 06:24 PM
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 /.
November 18th, 2012, 06:37 PM
oh yes i forgot about mysql_escape_string ill give it a try
Originally Posted by Storm2012
November 18th, 2012, 06:57 PM
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 ``.
November 19th, 2012, 08:22 AM
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
November 19th, 2012, 01:27 PM
never die your mysql_error on live server , very insecure
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());
November 19th, 2012, 07:50 PM