php折扣。由于某种原因,始终应用折扣

时间:2017-10-10 07:31:47

标签: php

在一个文件中

<?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!";
}

?>

在付款文件中

<?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>

我有的问题是为某人没有钥匙时的折扣代码创建一个基本案例

0 个答案:

没有答案