Php 选择表单-如果为空,则使用上次过账的值
对于这里的新手问题,我提前表示歉意 当前,我的第一个值是禁用的默认“选择”选项,当进行选择时,该选项将更改为选定选项 但是,如果用户在未重新选择的情况下再次提交,则该值默认返回,因为post为空。因此,如果有,是否有方法使用上一个值Php 选择表单-如果为空,则使用上次过账的值,php,html,forms,select,post,Php,Html,Forms,Select,Post,对于这里的新手问题,我提前表示歉意 当前,我的第一个值是禁用的默认“选择”选项,当进行选择时,该选项将更改为选定选项 但是,如果用户在未重新选择的情况下再次提交,则该值默认返回,因为post为空。因此,如果有,是否有方法使用上一个值 <select name="test_select" style="width: 110px"> <option disabled="disabled" selected="selected"> <?php
<select name="test_select" style="width: 110px">
<option disabled="disabled" selected="selected">
<?php
if(!empty($_POST['test_select'])){
echo $_POST[test_select'];}
else
echo "Select Option"; ?>
</option>
<?php $sql = mysql_query("SELECT test FROM test_settings");
while ($row = mysql_fetch_array($sql)){
?><option><?php echo $row['test']; ?></option><?php }?>
</select>
我想问题在于表单没有发送禁用的值
我将按如下方式编辑代码:
<select name="test_select" style="width: 110px">
<?php
if (empty($_POST['test_select']))
echo '<option selected="selected">Select Option</option>';
$sql = mysql_query("SELECT test FROM test_settings");
while ($row = mysql_fetch_array($sql)){
$selected = isset($_POST['test_select']) && $row['test'] == $_POST['test_select']
? ' selected="selected"'
: '';
echo '<option'.$selected.'>'.$row['test'].'</option>';
?>
</select>
这是事实,在不禁用的情况下,它确实可以工作。然而,经过第二次思考,我将需要维护post值以供进一步使用,这本身就是另一个问题;我可能需要使用会话。谢谢