开发者

Can't figure out why this isn't working? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifyi开发者_开发技巧ng this question so that it can be reopened, visit the help center. Closed 11 years ago.
<?php

$tireqty = $_POST['tireqty'];
$oilqty = $_POST['oilqty'];
$sparkqty = $_POST['sparkqty'];

$totalamount = 0.00;
define('TIREPRICE', 100);
define('OILPRICE', 10);
define('SPARKPRICE', 4);

$totalqty = 0;
$totalqty = $tireqty + $oilqty + $sparkqty;

i    f ($totalqty == 0) {
    echo "You did not enter anything in the boxes on the previous page.";
}
else {
    echo "<p>Order processed at ".date('H:i, jS F Y')."</p><br /><br />";
    echo '<p>Your order is as follows:</p>';
    echo $tireqty.' tires<br />';
    echo $oilqty.' bottles of oil<br />';
    echo $sparkqty.' spark plugs<br />';
    echo "Items ordered: ".$totalqty."<br />";

    if ($tireqty < 10) {
        $discount = 0;
    }
    elseif ($tireqty >= 10) && ($tireqty <= 49) {
        $discount = 0.05;
    }
    elseif ($tireqty >= 50) && ($tireqty <= 99) {
        $discount = 0.10;
    }
    elseif ($tireqty >= 100) {
        $discount = 0.15;
    }

    $totalamount = ($tireqty * TIREPRICE + $oilqty * OILPRICE + $sparkqty * SPARKPRICE) * (1+$discount);

    echo "Subtotal (Discount applied here): $".number_format($totalamount, 2)."<br />";

    $taxrate = 0.10;
    $totalamount = $totalamount * (1+ $taxrate);
    echo "Total including Tax: $".number_format($totalamount,2)."<br />";
}
?>

Any help would be appreciated.


I am a beginner so I might wrong but here elseif ($tireqty >= 10) && ($tireqty <= 49) I would use and extra bracket:

elseif (($tireqty >= 10) && ($tireqty <= 49)) {
...
}

Hope this is it:)


This is a terrible question but here goes... without knowing what's "not working" I can only guess:

i    f ($totalqty == 0) {

That's a syntax error. You probably meant:

if ($totalqty == 0) {

Likewise, here:

if ($tireqty < 10) {
        $discount = 0;
    }
    elseif ($tireqty >= 10) && ($tireqty <= 49) {
        $discount = 0.05;
    }
    elseif ($tireqty >= 50) && ($tireqty <= 99) {
        $discount = 0.10;
    }
    elseif ($tireqty >= 100) {
        $discount = 0.15;
    }

The entire conditions need to be enclosed in parens:

elseif (($tireqty >= 10) && ($tireqty <= 49)) {
    $discount = 0.05;
}
elseif (($tireqty >= 50) && ($tireqty <= 99)) {
    $discount = 0.10;
}
elseif ($tireqty >= 100) {
    $discount = 0.15;
}

It's possible there's a lot more things wrong here. Please edit your question and describe specifically what is not working, and what you've done to fix it, and what you need help with.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜