
Market
By: a guest on
Aug 21st, 2012 | syntax:
PHP | size: 1.76 KB | hits: 19 | expires: Never
<!DOCTYPE HTML>
<html>
<head>
<title>Mini Market</title>
</head>
<body>
<h1>Welcome in Hepic's Market</h1>
<form action="process.php" method="post">
<?php
$date=date("H:i:s, jS F Y");
echo "You came in my market:<br/>".$date;
?>
<table border="3">
<tr bgcolor="yellow">
<td width="150">Item</td>
<td width="15">Quantity</td>
</tr>
<tr bgcolor="red">
<td>Milk</td>
<td><input type="text" name="milk" size="14" /></td>
</tr>
<tr bgcolor="red">
<td>Oil</td>
<td><input type="text" name="oil" size="14" /></td>
</tr>
<tr bgcolor="red">
<td>Tomatoes</td>
<td><input type="text" name="tomatoes" size="14" /></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="SUBMIT" />
</td>
</tr>
</table>
</form>
<?php
$milk=(isset($_POST['milk']) ? $_POST['milk'] : 0);
$oil=(isset($_POST['oil']) ? $_POST['oil'] : 0);
$tomatoes=(isset($_POST['tomatoes']) ? $_POST['tomatoes'] : 0);
$AllItems=$milk+$oil+$tomatoes;
echo "Item ordered:".$AllItems."<br/>";
$totalammount=0.00;
define("MILKPRICE",2);
define("OILPRICE",5);
define("TOMATOESPRICE",3);
$totalammount=$milk*MILKPRICE+$oil*OILPRICE+$tomatoes*TOMATOESPRICE;
echo 'Subtotal: $'.number_format($totalammount,2).'<br/>';
$tax=1.10;
$totalammount*=$tax;
echo "Including tax: $".number_format($totalammount,2).'<br/>';
$output="Item ordered:".$AllItems."<br/>"."Milk:".$milk." Oil:".$oil." Tomatoes:".$tomatoes."<br/>"." Totalammount:$".$totalammount;
$filename="market.txt";
@ $fp=fopen($filename,'ab');
flock($fp,LOCK_EX);
if(!$fp)
{
echo "<p><strong>File can't open</p></strong>";
}
fwrite($fp,$output,strlen($output));
flock($fp,LOCK_UN);
fclose($fp);
echo"<p>Order is written</p>";
?>
</body>
</html>