Jump to content

[SOLVED] Giving options a title in forms


garry

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.