Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

HTTP/CSS/PHP: Create an html such as the following which will ask the user to en

ID: 3818255 • Letter: H

Question

HTTP/CSS/PHP:

Create an html such as the following which will ask the user to enter an order form. It will calculate the total based on the business logic: Total = Quantity *Unit_price - Discount + Shipping_cost This amount will then be used to calculate tax. The final result after plus tax will be divided by the number of payments entered by user. The business logic for shipping handling cost is calculated as follows $5.00 for Slow and steady... $9.95 for Put a move on it. $19.95 for I need it yesterday! Fill out this form to calculate the total cost: Fill out this form to calculate the total cost:

Explanation / Answer

calculator.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
   <title>Product Cost Calculator</title>
</head>
<body><!-- Script 4.1 - calculator.html -->
<div><p>Fill out this form to calculate the total cost:</p>

<form action="handle_calc.php" method="post">

<p>Price: <input type="text" name="price" size="5" /></p>

<p>Quantity: <input type="text" name="quantity" size="5" /></p>

<p>Discount: <input type="text" name="discount" size="5" /></p>

<p>Tax: <input type="text" name="tax" size="3" /> (%)</p>

<p>Shipping method: <select name="shipping">
<option value="5.00">Slow and steady</option>
<option value="8.95">Put a move on it.</option>
<option value="19.36">I need it yesterday!</option>
</select></p>

<p>Number of payments to make: <input type="text" name="payments" size="3" /></p>

<input type="submit" name="submit" value="Calculate!" />

</form>

</div>
</body>
</html>


handle_calc.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
   <title>Product Cost Calculator</title>
   <style type="text/css" media="screen">
       .number { font-weight: bold; }
   </style>
</head>
<body>
<?php // Script 4.2 - handle_calc.php
/* This script takes values from calculator.html and performs
total cost and monthly payment calculations. */

// Address error handling, if you want.

// Get the values from the $_POST array:
$price = $_POST['price'];
$quantity = $_POST['quantity'];
$discount = $_POST['discount'];
$tax = $_POST['tax'];
$shipping = $_POST['shipping'];
$payments = $_POST['payments'];

// Calculate the total:
$total = $price * $quantity;
$total = $total + $shipping;
$total = $total - $discount;

// Determine the tax rate:
$taxrate = $tax/100;
$taxrate = $taxrate + 1;

// Factor in the tax rate:
$total = $total * $taxrate;

// Calculate the monthly payments:
$monthly = $total / $payments;


$total=number_format($total,2);
$monthly=number_format($monthly,2);

// Print out the results:
print "<p>You have selected to purchase:<br />
<span class="number">$quantity</span> widget(s) at <br />
$<span class="number">$price</span> price each plus a <br />
$<span class="number">$shipping</span> shipping cost and a <br />
<span class="number">$tax</span> percent tax rate.<br />
After your $<span class="number">$discount</span> discount, the total cost is
$<span class="number">$total</span>.<br />
Divided over <span class="number">$payments</span> monthly payments, that would be $<span class="number">$monthly</span> each.</p>";

?>
</body>
</html>