Timb75 Posted February 12, 2009 Share Posted February 12, 2009 that are populated using the database. I receive this error: No database selected SELECT Name FROM Teams Name is a field inside the Teams table if this helps. Here is the code I am using: <?php $user = ""; $host = ""; $password = ""; $dbName = "olevetpo_polls"; /* make connection to database */ mysql_connect($host, $user, $password) OR DIE( "Unable to connect to database"); mysql_select_db($dbName); //did you forget this line? $sql = "SELECT Name FROM Teams"; $query = mysql_query($sql) or die(mysql_error() . "<br>$sql"); //use the or die(...) part ONLY IN DEVELOPMENT ?> <form action="action" method="post"> <select name="option"> <?php while ($row = mysql_fetch_array($result)) { echo "<option value=\"" . $row['Name'] . "\">" . $row['Name'] . "</option>\n"; } ?> </select> <input type="submit"> </form> I left the database name, but not the rest for obvious reasons. First, I am a big time noob when it comes to php, I found this code here at phpfreaks. I do know that this only shows one drop list.... With that said, I need some other help too.... I am trying to create a college football human poll, so I need 24 more of these drop downs (stacked on top of each other and with #1, #2, #3, etc preceeding the dropdowns), but only one submit, after the final list. How would I do this? Quote Link to comment https://forums.phpfreaks.com/topic/144908-solved-trying-to-create-drop-down-lists/ Share on other sites More sharing options...
rhodesa Posted February 12, 2009 Share Posted February 12, 2009 do you get any errors if you change this: mysql_select_db($dbName); //did you forget this line? to mysql_select_db($dbName) or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/144908-solved-trying-to-create-drop-down-lists/#findComment-760431 Share on other sites More sharing options...
steveh62 Posted February 12, 2009 Share Posted February 12, 2009 this might help I was trying to make labels and checkboxes in a similar way <?php $labels = array( 0 => '200mm x 200mm', 1 => '200mm x 300mm', 2 => '200mm x 400mm', 3 => '200mm x 500mm', 4 => '200mm x 600mm', ); foreach ($labels as $named1 => $label) { print '<label>' .$label. '</label><input id="sizes" name="sizes[' .$named1. ']" type="checkbox" value="' . $label. '" onclick="setChecks(this)"'; //if ($key == 0){ // print "checked"; //} print ' /><input id="price" name="price[' .$named1. ']" type="text" class="dropdown" /><br/>'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/144908-solved-trying-to-create-drop-down-lists/#findComment-760519 Share on other sites More sharing options...
Zane Posted February 12, 2009 Share Posted February 12, 2009 you have either mispelled the database name OR you are connecting to the wrong host. Those are the only two problems I can think of that can occur for a mysql_select_db. Quote Link to comment https://forums.phpfreaks.com/topic/144908-solved-trying-to-create-drop-down-lists/#findComment-760605 Share on other sites More sharing options...
Timb75 Posted February 13, 2009 Author Share Posted February 13, 2009 do you get any errors if you change this: mysql_select_db($dbName); //did you forget this line? to mysql_select_db($dbName) or die(mysql_error()); That works....thanks. Now for my nex question: What do I need to do to create more than 1 drop down list that are stacked in different rows? How would I create the table to do so? I know HTML, the PHP is what is kicking my butt. Quote Link to comment https://forums.phpfreaks.com/topic/144908-solved-trying-to-create-drop-down-lists/#findComment-760975 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.