开发者

missing a quote somewhere T_String error

This is driving me crazy i know its a simple error but either i added or left out a quote something

echo "<option ". ($data['language'] == "" ? 'selected=selected>-- Select --</option>' : 'value=$dat开发者_高级运维a['language'] selected=selected'");


Use

echo "<option ". ($data['language'] == "" ? "selected=selected>-- Select --</option>" : "value=".$data['language']." selected=selected");

There was an inconsistant use of quotes/inline variable inclusion (so there was a ' where there should be a ")


You can't do variable interpolation in single quotes, and especially when using single quotes as the delimiter.

echo "<option ". ($data['language'] == "" ? 'selected=selected>-- Select --</option>' : 'value=' . $data['language'] . ' selected=selected'");


Change:

'value=$data['language'] selected=selected'

Into:

'value="'.$data['language'].'" selected=selected'


echo "<option "
     . ($data['language'] == ""
     ? 'selected=selected>-- Select --</option>' :
     'value=$data['language'] selected=selected'" //< This line
     );

As you can see your using the same quotes as the selection from the $data array so you need to do:

echo "<option " . ($data['language'] == "") ? 'selected=selected>-- Select --</option>' : "value=\"" . $data['language'] . "\" \"selected=selected\"" );

a better solution would be:

if($data['language'] == "")
{
    echo '<option selected=selected>-- Select --</option>';
}else
{
    echo '<option selected=selected value="' . $data['language'] . '">-- Select --</option>';
}


echo "<option ". ($data['language'] == "" ? "selected=selected>-- Select --</option>" : "value='".$data['language'] . "' selected=selected");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜