How do I access the selected value of a drop down menu from html and get it in php? I’ve got a few fields like this:
<html>";
$sql = "SELECT * FROM table";
$stuff = mysql_query($sql) or die ("An error has occured.");
while($row = mysql_fetch_array($stuff))
{
$body.= "<option>".$row['value']."</option>\n";
}
$body.="<html>
I want to take this value and use it to filter the results I get from another query. How would I go about doing this?
In your current file
You need to add form around your select element. I have also fix some of your code so that the select tags are included and the option tags actually have a value set in them!
I have also added in a submit button so you can actually send the form.
In results.php
You now need to grab the filter from the POST values and use it in your query to filter the results like so:
All in one file: