garry Posted May 18, 2008 Share Posted May 18, 2008 I had another question and it's sorta hard to explain from the title so I'll try do the best I can. I have a form to add an artist where the user selects a genre from a drop down list (using the <select> tags). The select list is populated from the database and that all works fine and a drop down of all the genres will appear. But the problem comes when I'm trying to get the genre ID (the genre table contains both a genre and ID). How can I get the ID for the genre when I'm adding to the database? Here's the code I'm using: <html> <heading>Add Artist</heading> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> <table width="615" border="0"> <tr> <td width="144" height="32"><div align="right">Artist Name:</div></td> <td width="461"><input type="text" name="artist" value="" size="37" maxlength="37"/></td> </tr> <tr> <td><div align="right">Artist Description: </div></td> <td><textarea name="description" rows="10" cols="32" ></textarea> </td> </tr> <tr> <td><div align="right">Genre: </div></td> <td><select name="genre"> <? $query = "SELECT * FROM genres "; $result = mysql_query($query); while ($row = mysql_fetch_assoc($result)) { echo "<option>". $row['genre'] . "</option><br />"; } ?> </select> </td> </tr> <tr> <td height="33"><input name="submitted" type="hidden" value="1"></td> <td><input name="submit" type="submit" value="Submit" /></td> </tr> </table> </form> </html> Link to comment https://forums.phpfreaks.com/topic/106140-solved-giving-options-a-title-in-forms/ Share on other sites More sharing options...
marklarah Posted May 18, 2008 Share Posted May 18, 2008 <option value="foo1">Foo One</option> <option value="foo2">Foo Two</option> given that the select name is "bob" or whatever, when the user selects "Foo One", the value of bob will be foo1. Hope that helps Link to comment https://forums.phpfreaks.com/topic/106140-solved-giving-options-a-title-in-forms/#findComment-544065 Share on other sites More sharing options...
micmania1 Posted May 18, 2008 Share Posted May 18, 2008 <select> <option value="'.$genre_id.'">'.$genre.'</option> </select> Link to comment https://forums.phpfreaks.com/topic/106140-solved-giving-options-a-title-in-forms/#findComment-544069 Share on other sites More sharing options...
garry Posted May 18, 2008 Author Share Posted May 18, 2008 Works great. You guys are champions. Thanks Link to comment https://forums.phpfreaks.com/topic/106140-solved-giving-options-a-title-in-forms/#findComment-544076 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.