Monday, 15 September 2014

populate a select box with php mysql -



populate a select box with php mysql -

i'm having difficulty populating select box within form display existing "forenames" of nurses "nurses" table. tell me im doing wrong? in advance!

here form

<form method="post" action="insert.php"> <br> <tr><td align="left"><strong>nurse information</strong></td> </td> <tr> <td>nurse_name</td> <td><select name="valuelist"> <option value="valuelist" name="nurse_name" value='<?php echo $nurse_name; ?>'></option> </select></td> <tr>

the query should populate nurse_forename:

<html><head><title>connect database</title></head><body> <font size="4">query gets forename of nurse</font> <br><br><font size="4">choose name</font><br><br> <form action="insert.php" method="post"> <select name="valuelist">; <?php $value=$_post ["valuelist"]; $con = mysql_connect("localhost","root","") or die('could not connect: ' . mysql_error()); mysql_select_db("a&e", $con) or die('could not select database.'); $fetch_nurse_name = mysql_query("select distinct $nurse_name nurse"); $result = mysqli_query($con, $query) or die("invalid query"); while($throw_nurse_name = mysqli_fetch_array($fetch_nurse_name)) { echo '<option value=\"'.$nurse_name['nurse_name'].'">'.$throw_nurse_name['nurse_name'].'</option>'; } echo "</select>"; mysqli_close($con); ?> <input type="submit" value="submit"> </form></body></html>

try this:

<html><head><title>connect database</title></head><body> <font size="4">query gets forename of nurse</font> <br><br><font size="4">choose name</font><br><br> <form action="insert.php" method="post"> <select name="valuelist">; <?php $value=$_post ["valuelist"]; $con = mysql_connect("localhost","root","") or die('could not connect:'.mysql_error()); mysql_select_db("a&e", $con) or die('could not select database.'); $fetch_nurse_name = mysql_query("select distinct forename nurse"); while($throw_nurse_name = mysql_fetch_array($fetch_nurse_name)) { echo '<option value=\"'.$throw_nurse_name[0].'">'.$throw_nurse_name[0].'</option>'; } echo "</select>"; ?> <input type="submit" value="submit"> </form></body></html>

dont utilize mysql , mysqli together....you should utilize mysqli or pdo, not mix of both ;) ps: edited ;)

saludos.

php mysql forms select

No comments:

Post a Comment