Hi everyone,
I need help with a piece of code wich is supposed to update the stock quantity on table "products" each time a new transaction is entered in table "transactions".
When the transaction type is "purchase" the quantity entered should be added to the stock qty, and when the type is "sell" the quantity should be substracted from the stock quantity.
This is what I've done so far, and even though the transaction is entered, I can't manage to update the stocks in "products":
<?php
$db = mysql_pconnect("localhost", "root");
mysql_select_db("data",$db);
mysql_query("INSERT INTO transactions (type, idproduct, quantity) values ('$type', $idproduct, $quantity)",$db);
if ($type == 'purchase')
{
mysql_query("UPDATE products SET stock = stock + $quantity where idproduct=$idproduct;",$db);
}
else
{
mysql_query("UPDATE products SET stock = stock - $quantity where idproduct=$idproduct;",$db);
}
?>
Any advice should be highly appreciated...
Thanks!
LUIS