0

我试图保存用户在“POST”表单操作在同一页面上运行后选择的状态,但我不断收到意外的 T_IS_EQUAL,期待“}”错误。我错过了什么?

我有以下代码:

<select style='width:50px; float:left; position:relative; left:-160px; top:2px; border-radius:3px; ' project='statelist' class='statelist' name='statelist'>

$state = array( 'AZ','AL','AK','AR', 'CA','CO', 'CT','DE','DC','FL', 'GA', 'HI','ID','IL', 'IN','IA','KS','KY','LA','ME','MT','NV','NH','NJ','NM','NY','NC', 'ND','OH', 'OK', 'OR', 'MD','MA', 'MI','MN','MS', 'MO','PA', 'RI', 'SC','SD','TN', 'TX', 'UT', 'VT', 'VA','WA', 'WV','WI','WY');

foreach($state as $name) {
$selected = '';
if {$_POST['statelist'] == $name}{
$selected = 'selected';}
echo '<option value="'.$name.'"'.$selected.">{$name}</option>\n";
}
</select>
4

1 回答 1

1

你太高兴了。

if {$_POST['statelist'] == $name}{

应该

if ($_POST['statelist'] == $name){
于 2013-04-09T01:54:31.837 回答