Jump to content

Syntax error, unexpected T_ECHO


scheda

Recommended Posts

I'm getting a syntax error in this code.

 

Basically I'm printing out a form, and depending on the value of an option, I want "checked" to be printed out.

 

I was getting a syntax error by using the non-shorthand version of an if statement too.

 

Any ideas why?

 

'<input type="radio" name="position" value="1" '.(get_option("shPosition") == 1 ? echo "checked" .' /> Top   
<input type="radio" name="position" value="0" '.(get_option("shPosition") == 0 ? echo "checked" .' /> Bottom'

Link to comment
https://forums.phpfreaks.com/topic/211527-syntax-error-unexpected-t_echo/
Share on other sites

Since the content you posted is apparently being built in a string, which you are either assigning to a variable to be echoed later or directly echoing, you don't put an echo statement inside of it. You must also supply a value after the :

'<input type="radio" name="position" value="1" '.(get_option("shPosition") == 1 ? "checked" : '') .' /> Top   
<input type="radio" name="position" value="0" '.(get_option("shPosition") == 0 ? "checked" : '').' /> Bottom'

 

 

Since the content you posted is apparently being built in a string, which you are either assigning to a variable to be echoed later or directly echoing, you don't put an echo statement inside of it. You must also supply a value after the :

'<input type="radio" name="position" value="1" '.(get_option("shPosition") == 1 ? "checked" : '') .' /> Top   
<input type="radio" name="position" value="0" '.(get_option("shPosition") == 0 ? "checked" : '').' /> Bottom'

 

Oh that works perfectly.

 

Thank you for clarifying!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.