lbravo Posted June 4, 2008 Share Posted June 4, 2008 Hello, I've got an error 1064, and I know that means I've misused a reserved word, but for the life of me, I can't see it. Does anyone see what's wrong with this? for ($i=0, $n=sizeof($this->products); $i<$n; $i++) { $db->Execute('UPDATE products_licences SET orders_id='.$zf_insert_id . ' WHERE products_id='.$this->products[$i]['id'] . ' AND orders_id IS NULL' . ' LIMIT '.$this->products[$i]['qty'] ); $dbres = $db->Execute("SELECT licences_code FROM products_licences" . " WHERE products_id=".$this->products[$i]['id'] . " AND orders_id=".$zf_insert_id ); And here's the error message - 1064 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 ':7b8c4c37c00e45716db5456927e5ca75 AND orders_id IS NULL LIMIT 1' at line 1 in: [uPDATE products_licences SET orders_id=30 WHERE products_id=12:7b8c4c37c00e45716db5456927e5ca75 AND orders_id IS NULL LIMIT 1] I'm using MySQL 5.0.32-Debian_7etch3-log, Apache 2, and Debian Linux. Here's the table: CREATE TABLE `products_licences` ( -> `licences_id` int(10) unsigned NOT NULL auto_increment, -> `products_id` int(10) unsigned NOT NULL default '0', -> `products_attributes_id` int(10) unsigned default NULL, -> `licences_code` varchar(250) NOT NULL default '', -> `orders_id` int(10) unsigned default NULL, -> PRIMARY KEY (`licences_id`), -> KEY `product_id` (`products_id`,`orders_id`), -> KEY `product_attributs_id` (`products_attributes_id`) -> ) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=latin1 Thanks in advance! LBravo Quote Link to comment Share on other sites More sharing options...
fenway Posted June 4, 2008 Share Posted June 4, 2008 You need to quote that variable!!! Quote Link to comment Share on other sites More sharing options...
lbravo Posted June 4, 2008 Author Share Posted June 4, 2008 You need to quote that variable!!! um, WHICH variable? Quote Link to comment Share on other sites More sharing options...
lbravo Posted June 4, 2008 Author Share Posted June 4, 2008 I'm still having difficulties with this -- I added quotes to the '$i' variable, and now I get this error: 1064 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 'AND orders_id IS NULL LIMIT' at line 1 in: [uPDATE products_licences SET orders_id=37 WHERE products_id= AND orders_id IS NULL LIMIT ] Once again, here's the updated code: $db->Execute('UPDATE products_licences SET orders_id='.$zf_insert_id . ' WHERE products_id='.$this->products['$i']['id'] . ' AND orders_id IS NULL' . ' LIMIT '.$this->products['$i']['qty'] ); $dbres = $db->Execute('SELECT licences_code FROM products_licences' . ' WHERE products_id='.$this->products['$i']['id'] . ' AND orders_id='.$zf_insert_id ); Sorry I'm being such a dolt today... I appreciate any help for sure! LBravo Quote Link to comment Share on other sites More sharing options...
fenway Posted June 5, 2008 Share Posted June 5, 2008 Sorry, I meant the entire variable... that is, the string literal you're producing -- switch to double-quotes for the php string, singles for mysql strings: $db->Execute("UPDATE products_licences SET orders_id='".$zf_insert_id."'" . " WHERE products_id='".$this->products[$i]['id']."'" . " AND orders_id IS NULL" . " LIMIT ".$this->products[$i]['qty'] Quote Link to comment Share on other sites More sharing options...
lbravo Posted June 9, 2008 Author Share Posted June 9, 2008 Hi! Thanks so much for trying to help me! I've modified the code to match what you suggested, but I'm still getting an error: 1064 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 ':7b8c4c37c00e45716db5456927e5ca75 AND orders_id IS NULL' at line 1 in: [sELECT count(*) AS count FROM products_licences WHERE products_id=12:7b8c4c37c00e45716db5456927e5ca75 AND orders_id IS NULL] Here's the modified code: $db->Execute("UPDATE products_licences SET orders_id='".$zf_insert_id."'" . " WHERE products_id='".$this->products[$i]['id']."'" . " AND orders_id IS NULL" . " LIMIT ".$this->products[$i]['qty'] ); $dbres = $db->Execute('SELECT licences_code FROM products_licences' . " WHERE products_id='".$this->products[$i]['id']."'" . " AND orders_id=".$zf_insert_id ); I've been working on this for more than a week, and my nerves are starting to fray.... LOL - thanks again! Quote Link to comment Share on other sites More sharing options...
fenway Posted June 10, 2008 Share Posted June 10, 2008 You need to fix the second order_id... I didn't give you that one... $dbres = $db->Execute('SELECT licences_code FROM products_licences' . " WHERE products_id='".$this->products[$i]['id']."'" . " AND orders_id='".$zf_insert_id."'" ); 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.