Hello. I'm having a hard time with this. What i'm to do is discount the stock of certain product every time that a new entry is created (MYSql INSERT). So, the idea is INSERT the entry then UPDATE the Stock/Qty of the product that was sold.
Table Entrys for INSERT Table products UPDATE (idprod, stock, description)
This is my Qty input
<input type="text" name="txtQty<?=$i;?>" id="txtQty<?=$i;?>" value="1" size="3">
This is my MYSql Sentence after the INSERT
$sql_Qty = "UPDATE products SET stock = stock - '".$_POST['txtQty$i']."' WHERE idprod = '".$_POST['txtidp$i']."'";
$objQueryQty = mysql_query($sql_Qty);
Thanks!
Your UPDATE query should be this:
$sql_Qty = "UPDATE products SET `stock` = 'stock-".$_POST['txtQty'.$i]."' WHERE `idprod` = '".$_POST['txtidp'.$i]."'";
Solved! Just a very little fix in the Broken Heart Sentence.
$sql_Qty = "UPDATE products SET `stock` = stock-'".$_POST['txtQty'.$i]."' WHERE `idprod` = '".$_POST['txtidp'.$i]."'";