I have the code below but it does not do what i want it to do.
"UPDATE products SET quantity = quantity - 1 WHERE product = $'product'";
I have a data base called products with field quantity, now i do not know how to code such that the value stored in quantity will be decremented by number 1(one) or any other value of sold goods. I am trying to code a point of sale system for myself.
how do i fix it?
And how can i code it such that i can select multiple products and find their sum? i am able to do it for just one item at a time (assume i am selling two different products at the same time). the code i have for one item is below;
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>sale</title>
<?php
if (isset($_POST['GetPrice']))
{
//make connection to the database
$connect = mysql_connect("localhost", "root","");
if (!$connect)
{
die("database connection failed". mysql_error());
}
//make sure we’re using the right database
$select_db = mysql_select_db("lero_med");
if (!select_db)
{
die("database selection failed " .mysql_error());
}
$productQuantity= trim($_POST['productQuantity']);
$product = trim($_POST['product']);
$total = 0;
$query = "SELECT price FROM products WHERE product = '$product'";
$result2 = mysql_query($query2);
$result = mysql_query($query);
}
?>
<style type="text/css">
.auto-style1 {
margin-left: 16px;
}
.auto-style2 {
margin-left: 160px;
}
.auto-style3 {
margin-left: 20px;
}
.auto-style4 {
text-align: right;
}
</style>
</head>
<body>
<div class="auto-style4">
<form method="post" action="sell.php">
<fieldset name="Price" style="width: 448px; height: 164px">
<legend>Get Product Price</legend>
<br />
<select name="product" multiple="multiple" style="height: 23px; width: 117px;" class="auto-style3">
<option value="noSelection" selected="selected"> No Selection </option>
<option value="Panado"> Panado </option>
<option value="Compral"> Compral</option>
<option value="Peniciline"> Peniciline </option>
<option value="Granpar"> Granpar </option>
</select>
Quantity:
<input name="productQuantity" type="text" class="auto-style1" /> <br />
<br />
<br />
<input name="GetPrice" type="submit" value="Price?" class="auto-style2" />
<br/>
<?php
while ($row = mysql_fetch_array($result))
{
extract($row);
echo "Price per unit of " .$product . " is M " .$price ."<br/>";
}
$subtotal = ($price * $productQuantity);
if($productQuantity > -1)
{
echo "Price of " . $productQuantity ." ".$product . " is M" .sprintf("%0.2f", $subtotal ). "<br/>";
//$result2 = mysql_query($query2);
}
"UPDATE products SET quantity = quantity - 1 WHERE product = $'product'";
?>
</fieldset>
</form>
</div>
</body>
</html>