Storing a selection from a php dropdown derived from mySQL

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Mr T
Forum Newbie
Posts: 2
Joined: Tue Sep 08, 2009 4:53 pm

Storing a selection from a php dropdown derived from mySQL

Post by Mr T »

Very new to php and would like to know how I can store the selection from a dropdown box into a variable for use later. I have managed to create the dropdown from my MySQL db but don't know how to put this value into a variable. Code so far is:

Code: Select all

<?
mysql_connect("localhost", "root", "password") or die(mysql_error());
mysql_select_db("ff") or die(mysql_error());
 
$result = mysql_query("SELECT * FROM players");
$sql = "SELECT DISTINCT team FROM players";
$team=mysql_query($sql);
$options="";
 
echo '<select hteam="team"><option>select team</option>';
 
while($row=mysql_fetch_array($team)) {
$thing=$row['team'];
echo '<option>'.$thing.'</option>';
}
?>
Mr T
Forum Newbie
Posts: 2
Joined: Tue Sep 08, 2009 4:53 pm

Re: Storing a selection from a php dropdown derived from mySQL

Post by Mr T »

Bump...
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Storing a selection from a php dropdown derived from mySQL

Post by califdon »

We will appreciate your NOT "bumping" posts here. It definitely will NOT get you more attention, except as an annoying user.

Now, to answer your question, you have to put that <select> element within a <form> with a submit button that sends the form data to the same or a different PHP script that examines the $_POST variables, one of which will be the value of the option selected. The problem is, you haven't provided any values for your options. Read the following:
http://www.w3.org/TR/html401/interact/forms.html
http://www.w3schools.com/php/php_forms.asp
http://www.w3schools.com/TAGS/tag_Select.asp
Post Reply