【问题标题】:Can't figure out why this isn't working? [closed]无法弄清楚为什么这不起作用? [关闭]
【发布时间】:2011-08-25 13:00:13
【问题描述】:
<?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 />";
}
?>

任何帮助将不胜感激。

【问题讨论】:

  • 发布您遇到的错误
  • 不工作,我们的工作是找出原因和原因。有趣的态度。
  • 抱歉,我收到:“服务器错误网站在检索 localhost/processorder.php 时遇到错误。它可能因维护而关闭或配置不正确。”在铬。我对 PHP 很陌生,所以我不确定如何设置错误报告...
  • 我马上看到一件事:第一个中的一堆空格 if: i f ($totalqty == 0) {
  • 另外,如果你不知道如何编辑你的配置文件,这里是如何通过代码打开错误报告:php.net/manual/en/function.error-reporting.php

标签: php


【解决方案1】:

我是初学者,所以我可能会错,但这里 elseif ($tireqty >= 10) && ($tireqty

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

希望就是这样:)

【讨论】:

  • 干得好@Andras!您很可能会因此问题获得徽章 :-)
  • 非常感谢!现在我很高兴了解更多:) 和更多?:)))
【解决方案2】:

这是一个可怕的问题,但这里……不知道什么是“不工作”,我只能猜测:

i    f ($totalqty == 0) {

这是一个语法错误。您可能的意思是:

if ($totalqty == 0) {

同样,这里:

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;
    }

整个条件都需要用括号括起来:

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

这里可能有更多的问题。请编辑您的问题并具体说明哪些问题不起作用,您为解决问题所做的工作以及您需要帮助的地方。

【讨论】:

  • 当我在这里粘贴代码时,发生了间距问题。
  • @Dan:这是准确描述问题所在的一个很好的理由。如果你不知道,我们不知道你在问什么!
  • 好吧,如果你不正确地提问,这个地方会让你感觉很糟糕,对吧?只是我不知道出了什么问题,我还没有真正弄清楚如何获取错误消息(错误捕获?)...
  • @Dan:刚开始的时候可能会觉得有点苛刻,但试着回答几个问题你就会明白了。当有人(不仅仅是你!)说“这行不通。[代码]”时,这有点像将解决问题的全部责任推给了团队。这使得回答这个问题变得非常困难。在您的问题中进行简洁、清晰的解释将有助于获得更好的答案很长。不要因为一个问题而气馁!
  • 例如,即使说 what's 不起作用也会有所帮助。如果您不知道错误,请描述症状。如果您说“页面未显示”或“我收到错误消息 x”,那将有所帮助。 “不工作”可能是页面显示错误的价格。或者不显示价格。或者工作一半的时间。或者只是没有做你期望的事情。或价格为 3 时失败。或...或... :-)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-02-08
  • 1970-01-01
  • 1970-01-01
  • 2021-05-29
  • 1970-01-01
  • 1970-01-01
  • 2014-12-08
相关资源
最近更新 更多