1

This is a line inside the signup form which will pass the value entered via POST to a class called 'user' on success. On failure I want it to echo a failure message.

if(isset($_POST['email']))?$user->email=$_POST['email']:echo "no value found";

following is the error

Parse error: syntax error, unexpected '?' in C:\xampp\htdocs\login_API\Users\signup.php on line 15

code-mon
  • 71
  • 2
  • 10

1 Answers1

0

echo is a statement, not an expression, it can't be used as part of another expression.

You should use an ordinary if statement.

if (isset($_POST['email'])) {
    $user->email = $_POST['email'];
} else {
    echo "no value found";
}

Stylistically, you should only use a ternary expression if you're using the result of it somewhere, e.g.

$user->email = isset($_POST['email']) ? $_POST['email'] : "default@example.com";

Don't use it as a general replacement for if.

Barmar
  • 741,623
  • 53
  • 500
  • 612