Jump to content

Update data with dropdown menu?


eMonk

Recommended Posts

I'm not sure what to search for or if this can be done...

 

Let's say I have a mysql table named "genre". Now I have "Male" and "Female" in a dropdown menu like this in a form:

 

<select name="genre">

  <option>Male</option>

  <option>Female</option>

</select>

 

How would you display, for example, the option Female in a update.php file if that's the genre stored in the mysql database when you fetch the results?

Link to comment
https://forums.phpfreaks.com/topic/234627-update-data-with-dropdown-menu/
Share on other sites

I'm trying to update the genre in a php/mysql form though.

 

Is it possible to select the genre stored in the database, for example, Female and then have the other option under it (Male) so I can update it to Male if needed and vice versa?

 

I was thinking along the lines of:

 

<option><? echo($genre); ?></option>

 

But not sure how you would include the other options or if this can even be done.

give me just a moment i think i have some code written up for this...

 

 

here is the PHP portion...

 

 

<?php

$connect = mysql_connect('localhost' , 'root' , '') or die();

$db = mysql_select_db('database') or die();

$select = "SELECT genreID , genre_type FROM genre";

$result = mysql_query($select);

$options = "";

While ($row = mysql_fetch_array($result))
{

$genreID = $row["genreID"];
$genre = $row["genre_type"];

$options .= "<option=\"$genreID\">".$genre;
}
?>

 

Here is the HTML portion...

 

<html>

<table>
                <th>Genre</th>
                <tr>
                    <td><select name="genres"><?php echo $options; ?></td> 
                </tr>
            </table>


</html>



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.