Page 1 of 1

Storing a selection from a php dropdown derived from mySQL

Posted: Tue Sep 08, 2009 5:05 pm
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>';
}
?>

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

Posted: Wed Sep 09, 2009 4:58 pm
by Mr T
Bump...

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

Posted: Wed Sep 09, 2009 10:36 pm
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