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.4 - handle_calc.php #3
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) + $shipping) - $discount;
28.
29. // Determine the tax rate:
30. $taxrate = ($tax/100) + 1;
31.
32. // Factor in the tax rate:
33. $total = $total * $taxrate;
34.
35. // Calculate the monthly payments:
36. $monthly = $total / $payments;
37.
38. // Apply the proper formatting.
39. $total = number_format ($total, 2);
40. $monthly = number_format ($monthly, 2);
41.
42. // Print out the results:
43. print "<div>You have selected to purchase:<br />
44. <span class=\"number\">$quantity</span> widget(s) at <br />
45. $<span class=\"number\">$price</span> price each plus a <br />
46. $<span class=\"number\">$shipping</span> shipping cost and a <br />
47. <span class=\"number\">$tax</span> percent tax rate.<br />
48. After your $<span class=\"number\">$discount</span> discount, the total cost is
49. $<span class=\"number\">$total</span>.<br />
50. Divided over <span class=\"number\">$payments</span> monthly payments, that would be $<span class=\"number\">$monthly</span> each.</p></div>";
51.
52. ?>
53. </body>
54. </html>