Jump to content

Reducing sql value by one


petenaylor

Recommended Posts

Hi all

 

I have an SQL table with a quantity in and I am trying to write a piece of code to reduce the quantity by 1 each time. Here's my code:

 

$queryc = mysql_query(" SELECT FROM `voucher_codes` WHERE name = '".$voucherc."'");

$resultc = mysql_fetch_array ($queryc);

 

$voucherqtyvalue = $resultc['qty'];

 

$newvoucherqty = $voucherqtyvalue - 1;

 

$queryi = mysql_query(" UPDATE `voucher_codes` SET qty = '".$newvoucherqty."' WHERE name = '".$_SESSION['vouchercode']."'");

$resulti = mysql_result($queryi);

 

Instead, this changes the value to -1 in the table.

 

Please help!

 

Cheers

Pete

Link to comment
https://forums.phpfreaks.com/topic/219813-reducing-sql-value-by-one/
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.