Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6874369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:11:10+00:00 2026-05-27T04:11:10+00:00

How do I access the selected value of a drop down menu from html

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T04:11:10+00:00Added an answer on May 27, 2026 at 4:11 am

    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.

    $body .= '<select name="filter">
           <form action="" method="post">';            
    $sql = "SELECT * FROM table";
    $stuff = mysql_query($sql) or die ("An error has occured.");
    while($row = mysql_fetch_array($stuff))
    {
        $value = htmlentities($row['value'], ENT_COMPAT, 'UTF-8');
        $body .= '<option value="' . $value . '">' . 
                "$value</option>\n";
    }
    $body .= '</select>
        <input type="submit" />
        </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:

    $filter = '';
    if(isset($_POST['filter'])) {
        $filter = mysql_real_escape_string($_POST['filter']);
    }
    $SQL = "SELECT * FROM `table_name` WHERE `field` = '$filter'";
    // you can do the rest of the code from here :)
    

    All in one file:

    <?php
    if('POST' == $_SERVER['REQUEST_METHOD']) {
        $filter = '';
        if(isset($_POST['filter'])) {
            $filter = mysql_real_escape_string($_POST['filter']);
        }
        $SQL = "SELECT * FROM `table_name` WHERE `field` = '$filter'";
        // you can do the rest of the code from here :)
    }
    
    $body .= '<select name="filter">
           <form action="results.php" method="post">';            
    $sql = "SELECT * FROM table";
    $stuff = mysql_query($sql) or die ("An error has occured.");
    while($row = mysql_fetch_array($stuff))
    {
        $value = htmlentities($row['value'], ENT_COMPAT, 'UTF-8');
        $body .= '<option value="' . $value . '">' . 
                "$value</option>\n";
    }
    $body .= '</select>
        <input type="submit" />
        </form>';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this simple Select box that is suppose to store the selected value
I have a jsp with two drop down location and department. The value of
I have a drop down in a MVC View, which is some thing like
I'm trying to access the value of a selected radioButton. I have a list
I am working on a multi-select drop-down menu mentioned below <select class=form-input name=hideLineItemColumns_quote multiple=true
I want to access selected value of GridViewDataComboBoxColumn in server side at GridViewUpdated event.
I'm having problem accessing the text field in a selected value of Html.DropdownList. My
Hi I have this code in my view.. <%=Html.DropDownList(ProductTemplate,new SelectList(Model.ProductTemplate,Value,Text))%> I know if this
I have this code function getSelectData(id) { jQuery(id).change(function () { var value=''; jQuery(id+ option:selected).each(function
I'm developing a blackberry application to remotely access an external customer database. Selected employees

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.