Jump to content

help with MYSQL update


jammer

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.