php discounts. for some reason the discount is always applied
135
In one file
<?php
if (isset($_POST['submit']) && isset($_POST['discount'])) {
$discount = filter_input(INPUT_POST, "discount");
if (IsInjected($discount))
$errors .= "\n Bad discount value!";
if ($discount == "refund20") {
if (empty($errors)) {
$_SESSION["discount"] = $discount;
$errors .= "A $20 discount has been added to your purchase";
}
} else if ($discount == "refund25") {
if (empty($errors)) {
$_SESSION["discount"] = $discount;
$errors .= "A $25 discount has been added to your purchase";
}
}
$errors .= "\n Invalid discount code!";
}
?>
In pay file
<?php
$discount = $_SESSION["discount"];
// discounts applied
if ($discount == "refund25") {
$cost -= 25;
} else if ($discount == "refund20") {
$cost -= 20;
} else {
$cost -= 0;
}
?>
<p><span class='b'>Discount Code :</span> $discount</p>
the issue im having is creating a base case for the discount code for when someone doesn't have the key