php discounts. for some reason the discount is always applied


In one file

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


$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

People are also looking for solutions to the problem: php - Change str_replace to preg_replace in SELECT WHERE


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.