Jump to content

[SOLVED] Funky PHP/MYSQL update query syntax error


sculpy

Recommended Posts

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.