gillms1 Posted April 23, 2006 Share Posted April 23, 2006 Hi, if i have the following select menu in a form :<td>Section</td><td>:</td><td><select name="section"><option value="local">Local<option value="uni">Uni<option value="business">Business<option value="sport">Sport<option value="entertainment">Entertainment</select></td>is it possible to have the option values created by what is in my sql database (I have a table called section with those values in it)? If so could you please give me an idea as to how?Thanks, Sunny Quote Link to comment https://forums.phpfreaks.com/topic/8156-populating-form-select-menu-with-sql-data/ Share on other sites More sharing options...
mb81 Posted April 23, 2006 Share Posted April 23, 2006 [!--quoteo(post=367614:date=Apr 23 2006, 01:00 AM:name=gillms1)--][div class=\'quotetop\']QUOTE(gillms1 @ Apr 23 2006, 01:00 AM) [snapback]367614[/snapback][/div][div class=\'quotemain\'][!--quotec--]Hi, if i have the following select menu in a form :<td>Section</td><td>:</td><td><select name="section"><option value="local">Local<option value="uni">Uni<option value="business">Business<option value="sport">Sport<option value="entertainment">Entertainment</select></td>is it possible to have the option values created by what is in my sql database (I have a table called section with those values in it)? If so could you please give me an idea as to how?Thanks, Sunny[/quote][code]<td><select name="section"><?php$obj_sections = mysql_query("SELECT * FROM sections");while ($arr = mysql_fetch_assoc($obj_sections)) { echo "<option value=\"".$arr['sectionname']."\">".ucfirst($arr['sectionname'])."</option>";}?></select></td>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/8156-populating-form-select-menu-with-sql-data/#findComment-29752 Share on other sites More sharing options...
gillms1 Posted April 23, 2006 Author Share Posted April 23, 2006 Hi, Thanks for the reply, i changed the code so it looks like below :<?phpinclude 'admin_header.php';$dbcnx = @mysql_connect('localhost', 'root', '');if (!$dbcnx) { exit('<p>Unable to connect to the ' . 'database server at this time.</p>');}if (!@mysql_select_db('chronicle')) { exit('<p>Unable to locate the chronicle ' . 'database at this time.</p>');}?><table width="300" border="0" align="center" cellpadding="0" cellspacing="1"><tr><td><form name="form1" method="post" action="insertarticle_ac.php"><table width="100%" border="0" cellspacing="1" cellpadding="3"><tr><td colspan="3"><strong>Insert Article into MySQL Database </strong></td></tr><tr><td width="71">Editor</td><td width="6">:</td><td width="350"><input name="editor" type="text" id="editor"></td></tr><tr><td><select name="section"><?php$obj_sections = mysql_query("SELECT * FROM sections");while ($arr = mysql_fetch_assoc($obj_sections)) { echo "<option value=\"".$arr['sectionname']."\">".ucfirst($arr['sectionname'])."</option>";}?></select></td></tr><tr><td>Headline</td><td>:</td><td><input name="headline" type="text" id="headline"></td></tr><tr><td>Subheadline</td><td>:</td><td><input name="subheadline" type="text" id="subheadline"></td></tr><tr><td>Content</td><td>:</td><td><textarea cols=30 rows=10 name="content" type="text" id="content"></textarea></td></tr><tr><td colspan="3" align="center"><input type="submit" name="Submit" value="Submit"></td></tr></table></form></td></tr></table></html>however, i now get a blank screen? have i entered it incorrectly? Quote Link to comment https://forums.phpfreaks.com/topic/8156-populating-form-select-menu-with-sql-data/#findComment-29755 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.