How do i run a sql query in php to insert into a table and update another table. for example, when an inventory is entered, and submitted, sql query should run an insert statement to update the batch file and run update statement to update the totalquantityinstock (new quantity + existing quantity) in the product table. Hope my explanation could be understood.
Tables: Product (ProdId, Name, Cat, TtlQtyInStock,) and ProdInventory (InvID, ProdID, Qty)
Upon entering a new ProdInventory record in php form, the query should insert into ProdInventory and also update the TtlQtyInStock column in Product table).. What i want is currently the inventory of the product cld be 20, so when new inventory of 10 of same prod is added it shld sum 20 + 10.
My current query is:
$query = "INSERT INTO `ProdInventory (`ProdId`, `Quantity`) VALUES ('$ProdID', '$Quantity')";
"UPDATE product
SET QuantityInStock = (QuantityInStock + $Quantity)
WHERE ProductCode = $ProductCode";
I did browse thru some site but cldnt find something that suits my design. if someone cld help… 🙂
TIA.
the probable solution for that though not the best is by creating an Insert Trigger. so basically what it does is everytime an insert is made in the table the trigger fires and updates the value of the stock (it may be on the different table)