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>