i am new to php coding and i am getting an error please help me to solve this
Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' <option<?php if ( get_settings( $value['id'] ) == $option) { echo ‘ selected="selected" } elseif ($option == $value['std']) { echo ‘ selected="selected" } ?><?php echo $option; ?></option>

In { echo ' selected="selected" } , the PHP string isn't closed.

after closing { echo ' selected="selected";' } getting same error

<option<?php if ( get_settings( $value['id'] ) == $option) { echo ' selected="selected"'; } elseif ($option == $value['std']) { echo ' selected="selected"'; } ?><?php echo $option; ?></option>

This might be clearer:

<option <?php echo (get_settings($value['id']) == $option or $option == $value['std']) ? 'selected="selected"' : '' ?> >
    <?php echo $option; ?>
</option>

you alsso used a backtick ` in stead of a single quote '

ok getting same error

if ($key == get_settings($value['id']) ) { $checked = "checked="checked""; } else { $checked = ""; }

ok getting same error

Compare with the previous example. Am positive you can fix this yourself. Look at the quotes.

i tried to convert it with but error is same

if ($key == get_settings($value['id']) or $checked = "checked="checked":" ) else { $checked = ":" }
Member Avatar

diafol

You need to escape quotes when you nest the same types, e.g.

echo "He said \"Hello\" to me";

Quotes are not magic, the PHP interpreter sees this:

"checked=" -- STRING
checked -- NOT STRING
":" -- STRING

There's no concatenation and checked doesn't represent anything meaningful so it's an error. The embedded quotes need to be escaped, or you can use single quoted strings instead:

"checked=\"checked\":"
'checked="checked":'

The $checked = "checked="checked":" part also assigns to $checked when it looks more like you want to test for equality.

syntax error, unexpected T_ELSE

if($radio_setting != ”) {

if ($key == get_settings($value['id']) ) { $checked = "checked\="checked\""; } else { $checked = ""; }

} else {

if($key == $value['std']) { $checked = "checked="checked""; } else { $checked = ""; }
} ?>
<input type="radio" name="<?php echo $value['id']; ?>" value="<?php echo $key; ?>" <?php echo $checked; ?> /><?php echo $option; ?><br />
<?php }

This should do it:

<option <?php if ( get_settings( $value['id'] ) == $option)
              { 
                  echo 'selected="selected"'; 
              }
              if($option == $value['std'])
              { 
                  echo 'selected="selected"'; 
              } ?>><?php echo $option; ?></option>

You had also forgot to close the opening 'option' tag.

and what about my code line 3 and 9???

Member Avatar

diafol

@just
line 7 is mashed.

Also indent your code properly - it's difficult to follow.

and after implementing your code i am getting

Parse error: syntax error, unexpected '<' in