Forum Moderators: coopster
I am creating a form and have a select box to select a client name and client id from the Client table, created as below:
<select name="client">';
$query="SELECT clientid,name FROM client ORDER BY name";
$result=@mysql_query ($query);
while(($row=mysql_fetch_assoc($result))){
echo"<option value=\"{$row['clientid']}\">{$row['name']}</option>\n";
}
echo'
</select></td>
<td>
<input type="submit" name="clientsubmit" value="Select"/>
<input type="hidden" name="id" value="TRUE"/>
</td>
</tr>
</form>
How do I take the selected client id and store it as a variable (to be assigned as clientid in another table) and how do I make the selected client stay selected after the form has been posted?
Many thanks for any help.
Simon.
A) if the form of yours have mode=post, then $clientid=$_POST['client'];
Q)how do I make the selected client stay selected after the form has been posted?
A)
$query="SELECT clientid,name FROM client ORDER BY name";
$result=@mysql_query ($query);
while(($row=mysql_fetch_assoc($result)))
{
?>
<option value="<? echo $row['clientid'];?>"
<? if ($client==$row['clientid']) { echo " selected ";}?>
><? echo $row['name'];?></option>
<?
}
?>