我的PHP表单中的语法错误?

时间:2016-04-14 08:29:55

标签: php html mysql database forms

出现此错误:

  • 解析错误:语法错误,意外';'在 d:\的EasyPHP-DevServer-14.1VC9 \ websitestuff \ WWW \ PHP外形processor.php 第9行

代码:

$value = ($_POST['formEnquiry']) ? ($_POST['formName']) ? ($_POST['formTitle']) : '';

2 个答案:

答案 0 :(得分:0)

您似乎尝试使用两个三元运算符,但未指定" else子句"对于第一个。打破代码:

$value = ($_POST['formEnquiry'])
         ? ($_POST['formName'])
             ? ($_POST['formTitle'])
             : ''
         // You're missing a ':' (else) statement here, like
         : ''
;

将其编写为程序代码,它看起来像这样:

if ($_POST['formEnquiry']) {
    if ($_POST['formName']) {
        $value = $_POST['formTitle'];
    } else {
        $value = '';
    }
} else {
    // Because of the way an assignment through a ternary works,
    // there needs to be an else here, since you already wrote $value =
    // Without an else value, it would end up like $value = ;
    $value = '';
}

答案 1 :(得分:0)

试试这个:

$value = ($_POST['formEnquiry']) ? ($_POST['formName']) ? ($_POST['formTitle']) : '' : '';