Last active
September 30, 2016 11:35
-
-
Save sebgates/e770d2247b0bd41eb7f2e3869bc14beb to your computer and use it in GitHub Desktop.
Ex 5 PD file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (empty($_POST)){ | |
header("location:index.php"); #redirect to the index page | |
} | |
//get the data from the form | |
$product_description = $_POST["product_description"]; | |
$list_price = $_POST["list_price"]; | |
$discount_percent = $_POST["discount_percent"]; | |
if (!is_numeric($list_price) || !is_numeric($discount_percent)) { | |
if (!is_numeric($list_price)) { | |
$error_message = "The list price must be a number!<br/>"; | |
} | |
if (!is_numeric($discount_percent)) { | |
$error_message = "The discount percent must be a number!<br/>"; | |
} | |
header("location:index.php?error_message=".$error_message); #redirect to the index page | |
} | |
define('percentage', .01); | |
// print constant('percentage'); | |
//calculate the discount and discounted price | |
$discount = $list_price * $discount_percent * constant('percentage'); | |
$discount_price = $list_price - $discount; | |
//apply currency formatting | |
$list_price_f = "€".number_format($list_price,2); | |
$discount_percent_f = number_format($discount_percent)."%"; | |
$discount_f = "€".number_format($discount,2); | |
$discount_price_f = "€".number_format($discount_price,2); | |
?> | |
<!DOCTYPE html> | |
<!-- | |
To change this license header, choose License Headers in Project Properties. | |
To change this template file, choose Tools | Templates | |
and open the template in the editor. | |
--> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title></title> | |
<style> | |
#error { | |
color: red; | |
font-weight: bold; | |
} | |
label { | |
display: inline-block; | |
width: 150px; | |
font-weight: bold; | |
} | |
</style> | |
</head> | |
<body> | |
<!-- date formats available at: http://php.net/manual/en/function.date.php | |
Below is "This quote is valid from Wednesday 28th September, 2016" --> | |
<p>This quote is valid from <?php echo date('l jS F, Y'); ?></p> | |
<label>Product Description:</label> | |
<span><?php echo $product_description; ?></span><br/> | |
<label>List Price:</label> | |
<span><?php echo $list_price_f; ?></span><br/> | |
<label>Discount Percentage:</label> | |
<span><?php echo $discount_percent_f; ?></span><br/> | |
<label>Discount Amount:</label> | |
<span><?php echo $discount_f; ?></span><br/> | |
<label>Discount Price:</label> | |
<span><?php echo $discount_price_f; ?></span><br/> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment