price calculation based on quantity using php code example
Example: how to calculate quantity and price in php
1 <!doctype html>
2 <html lang="en">
3 <head>
4 <meta charset="utf-8">
5 <title>Product Cost Calculator</
title>
6 <style type="text/css">
7 .number { font-weight: bold; }
8 </style>
9 </head>
10 <body>
11 <?php
12
14
15
16
17
18 $price = $_POST['price'];
19 $quantity = $_POST['quantity'];
20 $discount = $_POST['discount'];
21 $tax = $_POST['tax'];
22 $shipping = $_POST['shipping'];
23 $payments = $_POST['payments'];
24
25
26 $total = $price * $quantity;
27 $total = $total + $shipping;
28 $total = $total - $discount;
29
30
31 $taxrate = $tax / 100;
32 $taxrate = $taxrate + 1;
33
34
35 $total = $total * $taxrate;
36
37
38 $monthly = $total / $payments;
39
40
41 print "<p>You have selected to
purchase:<br>
42 <span class=\"number\">$quantity</
span> widget(s) at <br>
43 $<span class=\"number\">$price</span>
price each plus a <br>
44 $<span class=\"number\">$shipping</
span> shipping cost and a <br>
45 <span class=\"number\">$tax</span>
percent tax rate.<br>
46 After your $<span
class=\"number\">$discount</span>
discount, the total cost is
47 $<span class=\"number\">$total</
span>.<br>
48 Divided over <span
class=\"number\">$payments</span>
monthly payments, that would be
$<span class=\"number\">$monthly</
span> each.</p>";
49
50 ?>
51 </body>
52 </html>