Last active
January 28, 2016 00:07
-
-
Save Synvox/1bbe2610506f66055629 to your computer and use it in GitHub Desktop.
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 | |
| // these will never show because they are never echo'ed in this file. | |
| $error_message = ""; | |
| if (empty($product_description)){ | |
| $error_message = 'Field cannot be blank.'; | |
| } else if (!is_numeric($list_price)){ | |
| $error_message = 'List price must be a valid number.'; | |
| } else if (!is_numeric($discount_percent)){ | |
| $error_message = 'Discount must be a valid number.'; | |
| } else { | |
| $error_message = ""; | |
| } | |
| // Display Errors | |
| if ($error_message !== "") { | |
| require('input1.php'); | |
| exit; | |
| } | |
| ?> | |
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <title>Product Discount Calculator</title> | |
| <link rel="stylesheet" type="text/css" href="main.css"> | |
| </head> | |
| <body> | |
| <main> | |
| <h1>Product Discount Calculator</h1> | |
| <label>Product Description:</label> | |
| <?php $product_description = filter_input(INPUT_POST, 'product_description');?> | |
| <?php echo htmlspecialchars($product_description);?><br> | |
| <label>List Price:</label> | |
| <span><?php $list_price = filter_input(INPUT_POST, 'list_price');?></span> | |
| <span><?php $list_price_f = "$". number_format($list_price, 2); ?></span> | |
| <span><?php echo htmlspecialchars($list_price_f); ?><br></span> | |
| <label>Standard Discount:</label> | |
| <span><?php $discount_percent = filter_input(INPUT_POST, 'discount_percent');?></span> | |
| <span><?php $discount_percent_f = $discount_percent."%";?></span> | |
| <?php echo htmlspecialchars($discount_percent_f); ?><br> | |
| <label>Discount Amount:</label> | |
| <?php $discount_amount = $list_price * $discount_percent * .01; ?> | |
| <?php $discount_amount_f = "$". number_format($discount_amount,2);?> | |
| <span><?php echo $discount_amount_f; ?></span><br> | |
| <label>Discount Price:</label> | |
| <?php $discount_price = $list_price - $discount_amount; ?> | |
| <?php $discount_price_f = "$". number_format($discount_price,2)?> | |
| <span><?php echo $discount_price_f; ?></span><br> | |
| <label>Sales Tax:</label> | |
| <?php $sales_tax = $discount_price * .08; // CHANGE $discount_price_f to $discount_price | |
| $sales_tax_f = "$". number_format($sales_tax,2); | |
| echo $sales_tax_f; | |
| ?><br> | |
| <label>Total:</label> | |
| <?php | |
| // CHANGE $discount_price_f to $discount_price | |
| // CHANGE $sales_tax_f to $sales_tax | |
| // Note, I think you meant + and not * | |
| // | | |
| // v | |
| $after_tax = $sales_tax + $discount_price; | |
| $after_tax_f = "$". number_format($after_tax,2); | |
| echo $after_tax_f; | |
| ?> | |
| </main> | |
| </body> | |
| </html> |
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
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <title>Product Discount Calculator</title> | |
| <link rel="stylesheet" type="text/css" href="main.css"> | |
| </head> | |
| <body> | |
| <main> | |
| <h1>Product Discount Calculator</h1> | |
| <form action="display_discount.php" method="post"> | |
| <?php | |
| $error_message = "";?> | |
| <div id="data"> | |
| <label>Product Description:</label> | |
| <input type="text" name="product_description"><br> | |
| <?php echo $error_message; ?> | |
| <label>List Price:</label> | |
| <input type="text" name="list_price"><br> | |
| <?php echo $error_message; ?> | |
| <label>Discount Percent:</label> | |
| <input type="text" name="discount_percent"><span>%</span><br> | |
| <?php echo $error_message; ?> | |
| </div> | |
| <div id="buttons"> | |
| <label> </label> | |
| <input type="submit" value="Calculate Discount"><br> | |
| </div> | |
| </form> | |
| </main> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment