Hello, everyone I am going to get right to the point.
I am trying to create this index.php with a discounted display of the calculation. Here is my display.php page code.
I have your classic $product_description, $list_price, and $discount_present. I think it might be working well the only problem that I am having is if the user is does not meet the validation requirements I am wanting the error message to display under the header.
<?php
//get the data from the form
$product_description = $_POST['product_description'];
$list_price = $_POST['list_price'];
$discount_percent = $_POST['discount_percent'];
$sales_tax_rate = $_POST['.08'];
//Validate product description
if(empty($product_description)){
$error_message = 'Product Description is required.';}
else if(!is_numeric($product_description)){
$error_message = 'Product Description is NOT suppose to be a number';}
//Validate list price
if(empty($list_price)){
$error_message = 'List Price is required.';}
else if ($list_price <= 0){
$error_message = 'List Price must be greater than zero';}
//Validate discount percent
if(empty($discount_percent)){
$error_message = 'Discounted Percent is required.';}
else if ($discount_percent <= 0){
$error_message = 'Discounted Percent must be greater than zero';}
//calculate the discount and discounted price
$discount = $list_price * $discount_percent * .08;
$discount_price = $list_price - $discount;
$sales_tax_amount = $discount_price * .08;
//apply currency formatting to the dollar and percent amounts
$list_price_formatted = "$".number_format($list_price, 2);
$discount_percent_formatted = $discount_percent."%";
$discount_formatted = "$".number_format($discount, 2);
$discount_price_formatted = "$".number_format($discount_price, 2);
$sales_tax_rate_formatted = $sales_tax."%";
$sales_tax_amount_formatted = "$".number_format($sales_tax_amount, 2);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3c.org/TR/xhtml1-transitional.dtd">
<html xmlns="http://www.w3c.org/1999/xhtml">
<head>
<title>Product Discount Calculator</title>
<link rel="stylesheet" type="text/css" href="styles.css" />
</head>
<body>
<div id="content">
<h1>Product Discount Calculator</h1>
<p class="error"><?php echo $error_message; ?></p>
<label>Product Description:</label>
<span><?php echo $product_description; ?></span><br>
<label>List Price:</label>
<span><?php echo $list_price_formatted; ?></span><br>
<label>Standard Discount:</label>
<span><?php echo $discount_percent_formatted; ?></span><br>
<label>Discount Amount:</label>
<span><?php echo $discount_formatted; ?></span><br>
<label>Discount Price:</label>
<span><?php echo $discount_price_formatted; ?></span><br />
<br />
<label>Sales Tax Rate:</label>
<span><?php echo $sales_tax_rate_formatted; ?></span><br />
<label>Sales Tax Amount:</label>
<span><?php echo $sales_tax_amount_formatted; ?></span>
</div>
</body>
</html>