How to load data on option box in php

Posted by user225269 on Stack Overflow See other posts from Stack Overflow or by user225269
Published on 2010-05-03T12:44:06Z Indexed on 2010/05/03 12:48 UTC
Read the original article Hit count: 168

Filed under:
|
|

I'm having trouble loading the mysql data on the html form option box using php. Here's my code:

<?php

  $con = mysql_connect("localhost","myuname","mypassword");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("school", $con);

 $idnum= mysql_real_escape_string($_POST['idnum']);

  $result = mysql_query("SELECT * FROM student WHERE IDNO='$idnum'");
?>

<?php while ( $row = mysql_fetch_array($result) ) { ?>

<tr>
<td width="30" height="35"><font size="2">*I D Number:</td>
<td width="30"><input  name="idnum"  type="text" maxlength="5" value="<?php echo $row["IDNO"]; ?>" readonly="readonly"></td>
</tr>

My problem is loading it here:

<td><font size="2">Gender</td>
<td>
    <select name="gender" id="gender">
        <font size="2">
        <option value="<?php echo $line['IDNO']; ?> "><?php $line['GENDER'] ; ?></option>



    </select></td></td>





The table looks like this:

    IDNO | GENDER  
    123  |  M
    321  |  F

What am I supposed to do?To load the exact gender corresponding to the IDNO?

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql