如果提交期间发生错误,则保留/显示选择输入的值



如何在submit失败后保留select input的选项?

<select name = "state" id="selector1" class="form-control1">
    <option value = "0">Select staff State of Origin</option>
    <?php
     $states_sql = "SELECT state, state_id FROM states ORDER BY state ASC LIMIT 0,36";
     $state_query = $cxn->query($states_sql);
    if($state_query->num_rows != 0){                                                        
       while($state = $state_query->fetch_object()){                                                                        
          <option value = "<?php echo htmlspecialchars($state->state_id); ?>">
            <?php echo htmlspecialchars_decode($state->state); 
     ?>
    </option>
    <?php
       }
    }                                                                   
    ?>

</select>

您的查询应如下所示

<select name = "state" id="selector1" class="form-control1">
    <option value = "0">Select staff State of Origin</option>
    <?php
     $states_sql = "SELECT state, state_id FROM states ORDER BY state ASC LIMIT 0,36";
     $state_query = $cxn->query($states_sql);
        if($state_query->num_rows != 0){                                                        
           while($state = $state_query->fetch_object()){                                                                        
                echo '<option value="'. htmlspecialchars($state->state_id).'">' .
                     htmlspecialchars_decode($state->state) .
                     '</option>';
            }
        }
    ?>
    </option>
</select>

最新更新