<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html><head>
<title>Saarland Beer Shop</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
</head>
<body>
<?php
function get_products() {
$db=mysql_connect('localhost','krichel','');
$query="SELECT * FROM beer_shop.products";
$result=mysql_query($query);
while($row=mysql_fetch_array($result)) {
$products[$row['id']]['name']=$row['name'];
$products[$row['id']]['price']=$row['price'];
}
return $products;
}
$products=get_products();
// euro rate
$euro_rate=1.21;
// stuff we need in the form
$form_greet='<h1>Please place your order</h1>';
$form_top="<form action=\"$_SERVER[PHP_SELF]\" method=\"get\"><table>";
$submit_check='</table><div><input type="hidden" name="submitted" value="1"/>';
$form_submit='<input type="submit" value="I order"/></div>';
$form_bottom='</form>';
// stuff we need it the order
$order_head="<h1>Results of your order</h1><div>\n";
$order_bottom="Thank you for your order. We will ship when we get your
check. Prosit!\n</div>";
if($_GET['submitted']) {
// print the form
// note that the form uses numbers as control
// names
$total_euro=0;
print $order_head;
foreach($_GET as $number => $amount) {
// find the product number for the handle
if($amount > 0 and $products[$number]) {
$pay=$amount*$products[$number][price];
print "$amount bottles of ";
print $products[$number][name];
print " is €$pay<br/>";
$total_euro+=$pay;
}
}
$total_dollar=$total_euro*$euro_rate;
$total_dollar=number_format($total_dollar,2);
print "The euro rate is $euro_rate<br/>\n";
print "Your bill is \$$total_dollar\n</div>";
}
else {
print $form_greet;
print $form_top;
$product_count=0;
foreach ($products as $prod) {
print "\n<tr><td>";
print $prod['name'];
print "</td><td>";
print "<input type=\"text\" name=\";
print $product_count;
print "\" maxlength=\"2\" size=\"2\"/>";
print "</td><td>@€";
print $prod['price'];
print "</td></tr>\n";
$product_count++; // don't forget!
}
print $submit_check;
print $form_submit;
print $form_bottom;
}
?>
<p>
<a href="http://validator.w3.org/check?uri=referer"><img
style="border: 0pt"
src="/valid-xhtml10.png"
alt="Valid XHTML 1.0!" height="31" width="88" /></a>
</p>
</body>
</html>