golgoj4 Posted August 30, 2007 Share Posted August 30, 2007 Hello. Im quite new to php and have been attempting to create a simple website. The problem is, one particular script is refusing to function and I have no idea why. the code is actually used in another part of the site, and it works fine...but not on this particular bit. this is the code that takes the information posted by the update page and is supposed to add it to the db. taking some advice I read in similar threads, I added and error message which tells me : 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 ''articles' SET title='biznatch!', desc='blah blah' WHERE id='21'' at line 1 <?php mysql_connect($host,$userName,$pass); $query= "UPDATE 'articles' SET title='$ud_title', desc='$ud_desc' WHERE id='$id' "; @mysql_select_db($db) or die( "Unable to select database"); $result= mysql_query($query); if($result) echo "Information updated" ; else echo "There was a problem with your update: " . mysql_error(); ?> So im quite stumped as to what im doing wrong. the variables are all populated, but I get this error unless i only update 1 column. :-\ thanks for any help. Quote Link to comment https://forums.phpfreaks.com/topic/67321-solved-update-non-functional-any-suggestions/ Share on other sites More sharing options...
AndyB Posted August 30, 2007 Share Posted August 30, 2007 DESC is a reserved word in MySQL. The best solution is to rename that (to something like descr). The sloppy solution/work-around is to write `desc` using backticks. Quote Link to comment https://forums.phpfreaks.com/topic/67321-solved-update-non-functional-any-suggestions/#findComment-337753 Share on other sites More sharing options...
akitchin Posted August 30, 2007 Share Posted August 30, 2007 furthermore, the table name should not be enclosed in single quotes. either do not enclose it in anything, or use back ticks for the table name as well. Quote Link to comment https://forums.phpfreaks.com/topic/67321-solved-update-non-functional-any-suggestions/#findComment-337754 Share on other sites More sharing options...
golgoj4 Posted August 30, 2007 Author Share Posted August 30, 2007 DESC is a reserved word in MySQL. The best solution is to rename that (to something like descr). The sloppy solution/work-around is to write `desc` using backticks. thanks! im going to give this a try Quote Link to comment https://forums.phpfreaks.com/topic/67321-solved-update-non-functional-any-suggestions/#findComment-337778 Share on other sites More sharing options...
golgoj4 Posted August 30, 2007 Author Share Posted August 30, 2007 furthermore, the table name should not be enclosed in single quotes. either do not enclose it in anything, or use back ticks for the table name as well. thank you as well. I did that in a desperate attempt to change things around. Im going to make these changes and try to avoid the reserved names. FIXED <?php mysql_connect($host,$userName,$pass); $query= "UPDATE articles SET title='$ud_title', descr='$ud_descr', notes='$ud_notes' , text='$ud_text' WHERE id='$id' "; @mysql_select_db($db) or die( "Unable to select database"); $result= mysql_query($query); if($result) echo "Information updated" ; else echo "There was a problem with your update: " . mysql_error(); ?> both of your suggestions were key to fixing it. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/67321-solved-update-non-functional-any-suggestions/#findComment-337779 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.