Im creating an e-commerce site.Need help with the code for transactions such that if a button is clicked,the quanity of the products is reduced in the products table.Say i had ten items and two are bought,the value in the quantity field should come to 8

7 Years
Discussion Span
Last Post by Borzoi

All you need to do is update the field.

Assuming your stock levels are labelled "Stock" in the database and the items are labelled "item":

  /*After obtaining the stock level from the database and putting it into the variable $stocklevel and placing the amount just bought into the variable $bought.*/
  $newstock = stocklevel - $bought;

  /*Update the database with the new stock level, assuming the item just bought has been placed in the $itembought variable.*/
  mysql_query("UPDATE tablename SET Stock = '$newstock' WHERE item = '$itembought'");
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.