xx_princess_xx Posted May 9, 2009 Share Posted May 9, 2009 I'm really new at the whole PHP thing, i have created a form that allows users to update a record from a database (mysql) at the moment the user has to select the ID they want to update what i am trying to do is create a drop down list with the available ID's for the user to select <?php $con = mysql_connect("localhost", "root", ""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("comreg098hassan", $con); $result = mysql_query("SELECT AID FROM Agents"); while($row_ID = mysql_fetch_array($result)) { echo $row_ID['AID']; echo "<br />"; }mysql_close($con); ?> <form> <select name="aid"><?php echo $row_ID['AID']; ?></select> </form> this code displays all the ID's on the page, but doesnt display in the drop down list, I would really appreciate your help thank-you Quote Link to comment https://forums.phpfreaks.com/topic/157501-solved-selecting-an-option-from-a-drop-down-list-from-mysql-database-using-php/ Share on other sites More sharing options...
wildteen88 Posted May 9, 2009 Share Posted May 9, 2009 The correct syntax for a drop down menu is <select name="aid"> <option value="value1">Value 1</option> <option value="value2">Value 2</option> <option value="value3">Value 3</option> </select> In PHP it'll be // start of form/menu echo '<form> <select name="aid">'; // produce the <option>'s while($row_ID = mysql_fetch_array($result)) { echo '<option value="'.$row_ID['AID'].'">'.$row_ID['AID'].'</option>'; } // end the menu/form echo '</select> </form>'; Quote Link to comment https://forums.phpfreaks.com/topic/157501-solved-selecting-an-option-from-a-drop-down-list-from-mysql-database-using-php/#findComment-830393 Share on other sites More sharing options...
xx_princess_xx Posted May 9, 2009 Author Share Posted May 9, 2009 thanks Quote Link to comment https://forums.phpfreaks.com/topic/157501-solved-selecting-an-option-from-a-drop-down-list-from-mysql-database-using-php/#findComment-830398 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.