Im completely new in php and in the process of trying to develop my project Im getting a problem in writting a code that can increase the quantity of the record by the value inserted in the textbox if the record exists otherwise a new row is added with the information from the form as inserted by the user.
Here's my code, Please help:
Here's my code, Please help:
Code:
$productId = (int)$_POST['txtItemID'];
$nwQty = "SELECT Quantity FROM stock WHERE itemCode = .'$productId'";
// check if the product is already
$solution = mysql_query($nwQty);
if (mysql_num_rows($solution) == 0)
{
// put the product in table
$sql = "INSERT INTO Stock(itemCode, Description, typeModel, quantity,SupName)
VALUES('$_POST[txtItemID]','$_POST[Descr]','$_POST[txtType]','$_POST[txtQty]', '$_POST[supname]')";
$result = mysql_query($sql);
}
else
{
// update product quantity in table
$sql = "UPDATE Stock
SET Quantity = Quantity + (" .$nwQty .")
WHERE itemCode = $productId";
$result = mysql_query($sql);
echo('Record Updated');
}
mysql_close($con);
?>
Comment