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 8685533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:36:02+00:00 2026-06-12T22:36:02+00:00

I have a simple php mysql search that searches a database, however, i cannot

  • 0

I have a simple php mysql search that searches a database, however, i cannot seem to get it to search the text from the search field and the category, but i only want it to search the category if selected,

this is my code that i have tried:

if ($search !== null){

    $sql = "SELECT * FROM people WHERE MATCH (lname,fname) AGAINST (:search IN BOOLEAN MODE) ORDER BY price ".$price." LIMIT ".$start.", ".$limit;

    $q   = $conn->prepare($sql) or die("failed!");
    // Bind the params to the placeholders
    $q->bindParam(':search', $search, PDO::PARAM_STR);
    $q->execute();
}


if ($search !== null && $category !== null){

    $sql = "SELECT * FROM people WHERE MATCH (lname,fname) AGAINST (:search IN BOOLEAN MODE) and category=:category ORDER BY price ".$price." LIMIT ".$start.", ".$limit;

    $q   = $conn->prepare($sql) or die("failed!");
    // Bind the params to the placeholders
    $q->bindParam(':search', $search, PDO::PARAM_STR);
    $q->bindParam(':category', $category, PDO::PARAM_STR);
    $q->execute();
}

however, this still ignores the category field option if selected! any ideas?

they are being set as follows:

   // Check and set category
$category = (!empty($_GET['category']) ? $_GET['category'] : null);

// Check and set search
if(!empty($_GET['search'])){
    $search = $_GET['search'];
}else{
    $search = null;
}
  • 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-12T22:36:07+00:00Added an answer on June 12, 2026 at 10:36 pm

    Do some debugging to make sure $search and $category are being set. That is most likely your problem. From the looks of it, $category should be getting set (since you said its coming from query string), but just check both to be sure. Something like:

    if($category !== null)
        die("category = $category");
    else {
        die("no category");
    }
    //do same test for $search
    

    If users are accessing this page from a link (<a href="search.php?category=Books">Books?</a>), I don’t see how $_GET['search'] would be set.

    I would suggest you change your if statements to be more efficient (only 1 should get executed):

    if ($search !== null){
        if($category !== null){
            //query with category
        }
        else {
            //query w/o category
        }
    }
    

    Also, I would use isset() to check if these variables are instantiated instead of empty().

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

Sidebar

Related Questions

I have a simple php page that displays data from a mysql database. I
I have a simple php file that gets info from mysql database display inside
I have a simple php/mysql script that stores in mysql database id, link, and
I have PHP code to do a simple MySQL database search with only two
I have a simple query (in a mySQL view) that php is using to
I have a sample page that uses 2 PHP files and a MySql database,
I have create a simple grid that retrieves data from a server through php.
I have a simple MySQL 5 database that consists of id - Int -
I have a site that displays data on travel products from a MySQL database.
I have a simple calendar on PHP and MySQL, it stores events in a

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.