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

  • SEARCH
  • Home
  • 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 7905875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T10:40:16+00:00 2026-06-03T10:40:16+00:00

I have created an HTML form with a search box and a drop down

  • 0

I have created an HTML form with a search box and a drop down list of 50 states in the USA. What I want is to let the user type in a keyword in the search box (email, subject, username, etc.) and select a state from the drop down. By selecting a state from the drop down, I want my PHP code to find the keyword from the search box only in that selected state. For example as a user, I would like to find “soccer” in the state of Washington and see a list of results.

In other words, how would I display results only in the selected state combined with my search form?

Here is a bit of my PHP code to give you all an idea of what I’m trying to accomplish.

// this is pulling the text that was typed in the html search box
$searchbox = $_POST['searchbox'];

// this is pulling the state from my HTML drop down menu
$state = $_POST['state'];

$searchboxresult = mysql_query("
  SELECT *
  FROM   table
  WHERE (ID      LIKE '%".$_POST['searchbox']."%')
     OR (stateID LIKE '%".$_POST['searchbox']."%')
     OR (city    LIKE '%".$_POST['searchbox']."%')
     OR (subject LIKE '%".$_POST['searchbox']."%')
     OR (email   LIKE '%".$_POST['searchbox']."%')
     OR (posting LIKE '%".$_POST['searchbox']."%')
     OR (skill   LIKE '%".$_POST['searchbox']."%')
     OR (event   LIKE '%".$_POST['searchbox']."%')
     OR (days    LIKE '%".$_POST['searchbox']."%')
     OR (url     LIKE '%".$_POST['searchbox']."%')
");

// and

$statedropdownresult = mysql_query("
  SELECT * FROM table WHERE stateID LIKE '%$state%'
");

Then I have a while loop that searches for everything and outputs the data. But I can’t get the states drop down to limit what the user is searching for. I can only get one or the other mysql_query to work in combination with my while loop, not both. For some reason, combining the queries into one using AND doesn’t seem to work either. Any ideas?

I know that the code is sloppy and there are security issues, however I will be going through to do a cleanup later on. If you need more details or clarification on something, I would be happy elaborate more!

  • 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-06-03T10:40:17+00:00Added an answer on June 3, 2026 at 10:40 am

    You could try something like this:-

    $sql ="SELECT * FROM table WHERE 1";
    
    if($_POST['searchbox'] != ''){
         $sql =" and (ID LIKE '%".$_POST['searchbox']."%') OR (stateID LIKE              
         '%".$_POST['searchbox']."%') OR (city LIKE '%".$_POST['searchbox']."%') OR   
         (subject LIKE '%".$_POST['searchbox']."%') OR (email LIKE  
         '%".$_POST['searchbox']."%') OR (posting LIKE '%".$_POST['searchbox']."%') OR  
         (skill LIKE '%".$_POST['searchbox']."%') OR (event LIKE  
         '%".$_POST['searchbox']."%') OR (days LIKE '%".$_POST['searchbox']."%') OR (url  
         LIKE '%".$_POST['searchbox']."%')";
    }
    if($state != ''){
        $sql .= " and stateID LIKE '%".$state."%'";
    }
    
      mysql_query($sql);
    

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When you have an ASP.Net MVC form created by Html.BeginForm(), how do fields inside
I have created a populated dropdown list in HTML. When the two dropdowns have
I have created my application that has search form and below contains results for
I want to create a search bar like one in this page http://dl.dropbox.com/u/333492/search/form.html If
I've created a search form for a script in php. Basicaly this form have
i have created partial view in MVC3. now i want to send text box
I have created a form (enquiry form) in HTML that posts to the following
I created drop down menu layouts as follows. <select name=search id=search > <option value=0>Please
i have create a form (so it's PHP and HTML hybrid-code). it has ability
I have created a html page in php and upon submission i validates that

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.