Jump to content

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>



This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.