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

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":

<?php
  
  /*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'");
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.