在这里,我创建了一个产品表和一个订单表。我想在下订单后立即输入产品ID,产品名称和价格将显示在表格上,一旦给出数量,总价将被计算,因此该特定产品ID的库存将相应更新。
<!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 http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Place Order</title>
<h1><center>ORDER MATTERS</center></h1>
</head>
<?php
if(isset($_POST['submit']))
{
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
echo "<marquee><h1> Order have been placed successfully.</h1></marquee>" ;
mysql_select_db("in", $con);
$sql="INSERT INTO orders (Name,Phone,Address,pid,Item,Price,Quantity,Total,Payment)
VALUES('$_POST[Name]','$_POST[Phone]','$_POST[Address]','$_POST[id]','$_POST[item]','$_POST[Price]','$_POST[quantity]','$_POST[Total]','$_POST[option]')";
mysql_query($sql,$con);
mysql_close($con);
}
?>
<body>
<form name="f1" action="orders.php" method="post">
<table style="background-color:#CCFFFF" border="4" align="center">
<tr>
<td>Name:</td>
<td> <input type="textbox" name="Name" required="required" /></td>
</tr>
<tr>
<td>Phone:</td>
<td bgcolor="#3399FF"> <input type="textbox" name="Phone" /></td>
</tr>
<tr>
<td>Address:</td>
<td bgcolor="#CCFF00"> <input type="textbox" name="Address" /></td>
</tr>
<tr>
<td>Enter Product id:</td>
<td> <input type="textbox" name="id" /></td><tr>
<td>Item:</td>
<td> <input type="textbox" name="item" /></td>
</tr>
<tr>
<td>Price:</td>
<td> <input type="textbox" name="Price" /></td>
</tr>
<tr>
<td>Qty.:</td>
<td bgcolor="#FFCCCC"> <input type="textbox" name="quantity" /></td>
</tr>
<tr>
<td>Total:</td>
<td> <input type="textbox" name="Total" /></td>
<td><? php echo $total; ?></td>
</tr>
<tr>
<td> Payment Method:</td>
<td>
<select name="option" id="option">
<option selected value="Cash on Delivery">Cash on Delivery
<option value="Cheque">Cheque
<option value="Online Payment">Online Payment</select></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Submit" name="submit" />
</td>
</tr>
</table>
</form>
</body>
</html>
<?php
//Trying the stock concept
$y=$_POST[id];
$qty=$_POST[quantity];
$x=(select price from products where id=($y));
$p=$x;
$total=$p*$qty;
(select stocks from products where id=$y)=$stockold;
$stock=$stockold-$qty;
stocks=$stock;
update stocks in products where id=$y;
?>