sculpy Posted December 17, 2007 Share Posted December 17, 2007 Good morning, I am having some rather strange issue with an SQL update syntax command. The syntax of the SQL query seems correct but this is the error I see when running my script: 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='test', img='faces0004.jpg', base_price=0.00, is_displayed=0, type_id=1 whe' at line 1 As I look through the code and examine my query I don't see any apparent issue. I have printed the query to the browser: update catalog set category_id='015', style_num='test3221', desc='test', img='faces0004.jpg', base_price='0.00', is_displayed='0', type_id='1' where style_num='test3' All of my variables are being passed properly through the POST collection. My code also looks correct: ini_set('error_reporting', E_ALL); ini_set('display_errors', 1); $category_id = $_POST['category']; $snum = $_POST['style_num']; $oldstyle = $_POST['oldstyle']; $base_price = $_POST['base_price']; $type_id = $_POST['item_type']; $is_displayed = $_POST['rgDisplay']; $img = $_FILES['img']['name']; $oldimg = $_POST['oldimg']; $desc = $_POST['desc']; if ($img == '') { $imgfile = $oldimg; } else { $imgfile = $img; } if (($category_id != '') && ($snum != '') && ($base_price != '') && ($type_id != '') && ($is_displayed != '') && ($desc != '')) { $query = "update catalog set category_id='$category_id', style_num='$snum', desc='$desc', img='$imgfile', base_price='$base_price', is_displayed='$is_displayed', type_id='$type_id' where style_num='$oldstyle'"; echo $query . '<br />'; $res = mysql_query($query) or die('Error: ' . mysql_error()); echo $res; The database table looks fine (to me) as well: CREATE TABLE `catalog` ( `item_id` int( unsigned zerofill NOT NULL auto_increment, `category_id` int(3) unsigned zerofill NOT NULL default '010', `style_num` varchar(15) NOT NULL default '', `desc` varchar(120) NOT NULL default '', `img` varchar(20) NOT NULL default 'notAvail.jpg', `base_price` float(5,2) NOT NULL default '0.00', `is_displayed` int(1) NOT NULL default '0', `type_id` int(4) NOT NULL default '0', PRIMARY KEY (`item_id`) ) ENGINE=MyISAM AUTO_INCREMENT=15 DEFAULT CHARSET=latin1; Whenever I have these sorts of problems I usually find an error in syntax but alas I am not seeing it. Also, I was using a snapshot of PHP6 along side of PHP 5.2.4 and have attempted to run the script on both versions of PHP with the same result (I thought it may have been a change I overlooked in the PHP6 change log). Also, it usually works to just go to bed and re-examine the code in the morning and then call yourself an idiot for not seeing the problem. This time I wasn't given the opportunity to insult myself. Any help "spotting the looney" would be much appreciated. Thank you. Quote Link to comment Share on other sites More sharing options...
rlindauer Posted December 17, 2007 Share Posted December 17, 2007 desc is a reserved word in MySQL. If you must use it, wrap backticks around it: `desc` Quote Link to comment Share on other sites More sharing options...
sculpy Posted December 17, 2007 Author Share Posted December 17, 2007 Thank you, I didn't even think of that. I will change the column name in my table and update my code. Quote Link to comment Share on other sites More sharing options...
revraz Posted December 17, 2007 Share Posted December 17, 2007 That would be better than using backticks, because desc means decending and you could get confused if you left it like that. Quote Link to comment Share on other sites More sharing options...
rlindauer Posted December 17, 2007 Share Posted December 17, 2007 ^^^ agreed Quote Link to comment Share on other sites More sharing options...
sculpy Posted December 17, 2007 Author Share Posted December 17, 2007 All solved. I think I'm going to like this forum alot. I will also try to help as I can. I can learn alot here.... Quote Link to comment 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.