sean04 Posted March 23, 2010 Share Posted March 23, 2010 Hey! So I have the following: <?PHP $Get_Sex = mysql_query("SELECT ID, Desc FROM gender") or die(mysql_error()); $Sex_Results = mysql_fetch_array($Get_Sex); while($val = mysql_fetch_array($Sex_Results)){ echo "<option value=$val[iD]>$val[Desc]</option>"; } ?> How come the drop down doesn't have any data in it? Thanks, Sean Link to comment https://forums.phpfreaks.com/topic/196200-populate-a-drop-down-with-mysql-data/ Share on other sites More sharing options...
Rustywolf Posted March 23, 2010 Share Posted March 23, 2010 DESC is a mysql function change Desc to description in mysql and querys Also, add "or DIE(mysql_error())" to the end of mysql queries its a good practice for finding errors Link to comment https://forums.phpfreaks.com/topic/196200-populate-a-drop-down-with-mysql-data/#findComment-1030330 Share on other sites More sharing options...
The Little Guy Posted March 23, 2010 Share Posted March 23, 2010 Try this: echo "<option value=\"{$val['ID']}\">{$val['Desc']}</option>"; Link to comment https://forums.phpfreaks.com/topic/196200-populate-a-drop-down-with-mysql-data/#findComment-1030335 Share on other sites More sharing options...
sean04 Posted March 23, 2010 Author Share Posted March 23, 2010 Thanks for the replies! Still no luck.. This is what its looking like: <form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post"> Email: <input type="text" name="email" size="30" maxlength="25"> Password: <input type="password" name="password" size="30" maxlength="25"> Confirm Password: <input type="password" name="cpassword" size="30" maxlength="25"> Screen Name: <input type="text" name="screenname" size="30" maxlength="55"> Gender: <select name="gender" value="">Gender</option> <?PHP $Get_Sex = mysql_query("SELECT ID, Description FROM gender") or die(mysql_error()); $Sex_Results = mysql_fetch_array($Get_Sex); while($val = mysql_fetch_array($Sex_Results)){ echo "<option value=\"{$val['ID']}\">{$val['Description']}</option>"; } ?> </select> <input type="submit" value="Register"> </form> I know its not to neat right now sorry Link to comment https://forums.phpfreaks.com/topic/196200-populate-a-drop-down-with-mysql-data/#findComment-1030337 Share on other sites More sharing options...
The Little Guy Posted March 23, 2010 Share Posted March 23, 2010 Your using the wrong param for your fetch array in the while loop... <?php $Get_Sex = mysql_query("SELECT ID, Description FROM gender") or die(mysql_error()); while($val = mysql_fetch_array($Get_Sex)){ echo "<option value=\"{$val['ID']}\">{$val['Description']}</option>"; } ?> Link to comment https://forums.phpfreaks.com/topic/196200-populate-a-drop-down-with-mysql-data/#findComment-1030338 Share on other sites More sharing options...
sean04 Posted March 23, 2010 Author Share Posted March 23, 2010 Thank you! Works great! Thought it had to do with something like that as the error mentioned it Didn't know what to do exactly though, Thanks again! Link to comment https://forums.phpfreaks.com/topic/196200-populate-a-drop-down-with-mysql-data/#findComment-1030340 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.