PeetZ PeetZ - 4 months ago 9
PHP Question

PHP - Using ternary operator in echo

I want to use a ternary operator within an

echo
, but it keeps giving an error:

Here is the code I am using:

echo'<input type="text" name="name" value="'.(isset($_POST["name"]) ? $_POST["name"] : "".'"/>';


Can somebody help me understand what I am doing wrong?

Returns Error:


Parse error: syntax error, unexpected ';' in ........

Answer

You just forgot your closing parenthesis :

echo '<input type="text" name="name" value="'.(isset($_POST["name"]) ? $_POST["name"] : "").'"/>';