以下是我的 html 表单的一部分。如果表单显示错误,那么我想选择用户选择的字段。但不幸的是,它对我不起作用。你们能帮我吗?
我的html表单:
<select class="td" name="class_name">
<option value="">--Select class--</option>
<?php
$class = mysql_query("SELECT * FROM e_class");
while($res = mysql_fetch_array($class))
{
$class_name_ed = $res['class_name'];
$class_id_ed = $res['class_id'];
?>
<option value="<?php echo "$class_name_ed"; ?>" <?php
if(isset($_POST['class_name']) == "$class_name_ed") echo 'selected = "selected"'; ?>>
<?php echo $class_name_ed; ?></option>";
<?php
}
?>
</select>
但是,如果我查看源文件,那么我可以看到以下内容。它已选中所有字段
<select class="td" name="class_name">
<option value="">--Select class--</option>
<option value="Three" selected = "selected"> Three</option>";
<option value="Four" selected = "selected"> Four</option>";
<option value="Five" selected = "selected"> Five</option>";
</select>
更新: 如果选项看起来像那么我该怎么办:
<option value="<?php echo "$class_name_ed | $class_id_ed"; ?>" <?php if
(isset($_POST['class_name']) && ($_POST['class_name'] == $class_name_ed)) echo
'selected = "selected"'; ?>> <?php echo $class_name_ed; ?></option>