卡住故障排除复合IF语句


Stuck Troubleshooting Compound IF Statement

我是一名经验丰富的程序员,但不是PHP开发人员。我被要求对以下代码进行故障排除,但看不出问题是什么。这个IF语句有效:

<?php
    if ($ice_cream_social == 'yes') {
        $registration_price = "58.00";
    }
?>

然而,有问题的页面需要一些复合IF语句来测试表单元素是否已被检查并相应地调整价格。这段代码不起作用,它不会给出错误——但IF不会执行:

<?php
    if ($ice_cream_social == 'yes' AND $registration_type == 'Banquet and Conference') {
        $registration_price = "78.00";
?>

使用开发人员工具,我已经验证了表单字段是从HTML传递的,代码的变量名称和值拼写正确,我可以成功测试任何一个ONE变量的值。似乎当使用上面显示的语法添加第二个或第三个测试时,测试失败,IF也不会运行。基于我对PHP语法的有限理解和一些谷歌搜索,代码在我看来是正确的(并且没有产生任何错误),但我想我遗漏了一些关于为什么这不起作用的东西。

有人能告诉我,如果我的代码示例中缺少了一些明显的东西,会导致if无法运行吗?我没有包含更多的代码,因为这是一组混乱的代码中的一部分:)

谢谢!

在我看来,在elseif上没有逻辑检查,所以你要么需要将其更改为else,要么添加一个检查(如果你打算的话)elseif($registration_price>0)

我用这个代码来测试:

<?php
$registration_price = '';
$ice_cream_social = 'yes';
//$ice_cream_social = 'no';
$registration_type = 'Banquet and Conference';
//$registration_type = 'Something else';
if ($ice_cream_social == 'yes') {
    $registration_price = "58.00";
} else {
    $registration_price = "not defined";
}        
echo $registration_price;
if ($ice_cream_social == 'yes' && $registration_type == 'Banquet and Conference') {
    $registration_price = "78.00";
} elseif( 1 > 0) {
    $registration_price = "1 million dolars!";
} else {
    $registration_price = "not defined";
}
echo $registration_price;