0

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>

6
Contributors
14
Replies
15
Views
5 Years
Discussion Span
Last Post by justzamir
0

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

0
<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>
0

ok getting same error

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

ok getting same error

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

0

i tried to convert it with but error is same

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

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

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

Edited by diafol: n/a

0

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.

0

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 }

Edited by justzamir: n/a

0

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.

0

@just
line 7 is mashed.

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

Edited by diafol: n/a

0

and after implementing your code i am getting

Parse error: syntax error, unexpected '<' in
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.