jammer Posted April 6, 2008 Share Posted April 6, 2008 hey i am trying to call a function to update a price i have tried a few different things and still no luck, any ideas? when i do the following it updates my prices but changes all the prices in the DB to 0.00 public function updatePrice( $product ) { $cx = Database::connect(); $table = self::$table; $price = $product['price']; if ( !$cx->query( "UPDATE $table SET price = '$price'") ) throw new Exception($cx->error); } When i do the following(also tried some other commands) it normally gives the following error: Fatal error: Uncaught exception 'Exception' with message '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 '(price) VALUES ('')' at line 1' in public_html/PhpStore/model/Product.php:34 Stack trace: #0 /public_html/PhpStore/admin/upPrice.php(10): Product::updatePrice(Array) #1 {main} thrown in /public_html/PhpStore/model/Product.php on line 34 public function updatePrice( $product ) { $cx = Database::connect(); $table = self::$table; $price = $product['price']; if ( !$cx->query( "UPDATE $table (price) VALUES ('$price')") ) throw new Exception($cx->error); Link to comment https://forums.phpfreaks.com/topic/99788-help-with-mysql-update/ Share on other sites More sharing options...
benjaminbeazy Posted April 6, 2008 Share Posted April 6, 2008 your update query will update all records if you don't have where clause. it should be something like... if ( !$cx->query( "UPDATE $table SET price = '$price' WHERE id=$id") Link to comment https://forums.phpfreaks.com/topic/99788-help-with-mysql-update/#findComment-510338 Share on other sites More sharing options...
jammer Posted April 6, 2008 Author Share Posted April 6, 2008 yea thanks i figured that out but now for some reason it just isn't updating the price, well the variable is updating just not to the DB, i dunno too tired, i'll try to figure it out tomorrow Link to comment https://forums.phpfreaks.com/topic/99788-help-with-mysql-update/#findComment-510345 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.