我有一個名爲reg.php的表單,它的動作是reg.php,我希望點擊提交時選定的下拉值要保持選中,我已經完成的工作如下下拉註冊表單不會在提交時刷新,如果有錯誤(在驗證的情況下)
<?php
if($_POST['registerbtn']){
$selected_value = $_POST['selectID'];
$query = mysql_query("SELECT linecard_name FROM selection WHERE select_id = '$selected_value'");
$rows=mysql_fetch_assoc($query);
$linecard_name= $rows['linecard_name'];
$sql = "SELECT select_id, linecard_name FROM selection " . "ORDER BY linecard_name";
$rs = mysql_query($sql);
while($rownw = mysql_fetch_array($rs)){
if( $rownw['linecard_name'] == $linecard_name) {
$options = "<option selected =selected value=".$rownw['select_id']."> " .$rownw['linecard_name']. " </option> ";
}
}
}
require("./connect.php");
$sql = "SELECT select_id, linecard_name FROM selection ". "ORDER BY linecard_name";
$rs = mysql_query($sql);
while($rownw = mysql_fetch_array($rs)){
$options .= "<option value = ".$rownw['select_id']." > ".$rownw['linecard_name']. " </option> ";
}
mysql_close() ;
$form = "<form action='./reg.php' method='post'>
<table>
<tr>
<td> </td>
<td> <font color='red'> $errormsg </font> </td>
</tr>
<tr>
<td> Select Linecard </td>
<td> <Select name='selectID' > <option value = '0'> Select from here </option> $options </select></td>
<tr>
<td > <input type='submit' name='registerbtn' value='Register' /> </td>
</tr>
</table>
檢查我的回答..之後,就是你想要的嗎? – sujal
我會看到給我幾分鐘 – Sparkle