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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:50:04+00:00 2026-06-14T13:50:04+00:00

I am having trouble searching multiple columns in a MySQL database table with user

  • 0

I am having trouble searching multiple columns in a MySQL database table with user input from a form.

Table in database is called vehicles and has 4 fields/columns: year, make, model, and option

The user inputs their search criteria from a form which I put into the $input variable.

Below is my code which doesn’t work. It returns a boolean error:

(Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given)

$query = ("SELECT * FROM vehicles WHERE year LIKE '%$input%' OR make LIKE '%$input%' OR model LIKE '%$input%' OR option LIKE '%$input%'");

$result = mysql_query($query);

Yet, when I remove the final OR from the query, it works fine, but only searches the year, make, and model fields:

$query = ("SELECT * FROM vehicles WHERE year LIKE '%$input%' OR make LIKE '%$input%' OR model LIKE '%$input%'");

$result = mysql_query($query);

How do I get the query to search all 4 fields/columns? What am I missing?

Is there an easier way to have an entire table (all columns in the table) be searched for a users’s input?

Really appreciate any help you can give me.

  • 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-14T13:50:06+00:00Added an answer on June 14, 2026 at 1:50 pm

    “option” is a reserved word in mysql, see here. So, your query actually fails and returns a boolean false instead of a resource. Rename the column or use “ around it like this

    $query = ("SELECT * FROM vehicles WHERE year LIKE '%$input%' OR make LIKE '%$input%' OR model LIKE '%$input%' OR `option` LIKE '%$input%'");
    

    Also be sure to use proper escaping to be safe against SQL Injection.

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

Sidebar

Related Questions

I have been having trouble searching through a MySQL table, trying to find entries
I am trying to get results from a MySQL database by searching multiple terms
Having trouble getting my form to UPDATE records in my database even after searching
Having trouble framing this assertion in Rspec for my rails app. A User has
I don't know a lot about MYSQL and am having trouble designing my database
I'm still having trouble searching for technologies that are stored in a separate table,
I'm not sure what this is called so I'm having trouble searching for it.
I'm not sure what this is called, which is why I'm having trouble searching
I'm having some trouble searching a SQLite database in my Android app. I use
I am having some trouble searching for what I want to do. I am

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.