Forum Moderators: coopster
Can anyone please help me with this sql query?
This code is for use in a shopping cart, I am not sure how to get it to subtract '1' from the 'quantity' row in the table.
[php]
include("../CMS/script-files/db-connect.php");
$SQL = " UPDATE products SET";
$SQL = $SQL . " quantity = '? MINUS 1' WHERE id = '$id'";
#execute SQL statement
$result = mysql_db_query($db,"$SQL",$cid);
# check for error
if (!$result) { echo("ERROR: " . mysql_error() . "\n$SQL\n"); }
mysql_close($cid);
[/php]
UPDATE table SET field='a string' WHERE.....
to enable quantity -1 to work, you have to use number data types such as Byte,Integer etc...., so it would be like:
UPDATE table SET field=field-1 WHERE.....
Take note of the missing quote. Quotes are only used when filling in or comparing string while when you deal with numeric data types DO NOT use quotes.
Regards
AndreJul