1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4. <head>
5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
6. <title>Product Cost Calculator</title>
7. <style type="text/css" media="screen">
8. .number { font-weight: bold;}
9. </style>
10. </head>
11. <body>
12. <?php // Script 4.3 - handle_calc.php #2
13. /* This script takes values from calculator.html and performs
14. total cost and monthly payment calculations. */
15.
16. // Address error handling, if you want.
17.
18. // Get the values from the $_POST array:
19. $price = $_POST['price'];
20. $quantity = $_POST['quantity'];
21. $discount = $_POST['discount'];
22. $tax = $_POST['tax'];
23. $shipping = $_POST['shipping'];
24. $payments = $_POST['payments'];
25.
26. // Calculate the total:
27. $total = $price * $quantity;
28. $total = $total + $shipping;
29. $total = $total - $discount;
30.
31. // Determine the tax rate:
32. $taxrate = $tax/100;
33. $taxrate = $taxrate + 1;
34.
35. // Factor in the tax rate:
36. $total = $total * $taxrate;
37.
38. // Calculate the monthly payments:
39. $monthly = $total / $payments;
40.
41. // Apply the proper formatting.
42. $total = number_format ($total, 2);
43. $monthly = number_format ($monthly, 2);
44.
45. // Print out the results:
46. print "<div>You have selected to purchase:<br />
47. <span class=\"number\">$quantity</span> widget(s) at <br />
48. $<span class=\"number\">$price</span> price each plus a <br />
49. $<span class=\"number\">$shipping</span> shipping cost and a <br />
50. <span class=\"number\">$tax</span> percent tax rate.<br />
51. After your $<span class=\"number\">$discount</span> discount, the total cost is
52. $<span class=\"number\">$total</span>.<br />
53. Divided over <span class=\"number\">$payments</span> monthly payments, that would be $<span class=\"number\">$monthly</span> each.</p></div>";
54.
55. ?>
56. </body>
57. </html>