-1

Getting this error:

  • Parse error: syntax error, unexpected ';' in D:\EasyPHP-DevServer-14.1VC9\websitestuff\www\php-form-processor.php on line 9

The code:

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

2 Answers2

0

You appear to be trying to use two ternary operators, yet are not specifying an "else clause" for the first one. Breaking the code down:

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

Writing it as procedural code, it would look like this:

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 = '';
}
Oldskool
  • 34,211
  • 7
  • 53
  • 66
0

Try this:

$value = ($_POST['formEnquiry']) ? ($_POST['formName']) ? ($_POST['formTitle']) : '' : '';
prava
  • 3,916
  • 2
  • 24
  • 35