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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:22:57+00:00 2026-06-08T20:22:57+00:00

So I am try ing to create a MySQL command to search a table.

  • 0

So I am try ing to create a MySQL command to search a table. What I want it to do is:

My table has 4 columns: id, categories, brands, names.

In php/html
on the search page the user selects a category from a dropdown. This is the category so this is posted as category to the search page. then thy type in a keyword into the text box. This is posted keyword to the search page.

I want to make a MySQL command that selects the category in categories posted then searches those selected rows for my posted keyword in the brands, and names columns

Here is what I have tried:

"SELECT brands, names 
   FROM tableName 
  WHERE categories LIKE".$_GET['category']." 
    AND (brands LIKE ".$_GET['keyword']." 
     OR names LIKE ".$_GET['keyword'].");";
  • 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-08T20:22:59+00:00Added an answer on June 8, 2026 at 8:22 pm

    You need quotes around strings in SQL. Try this:

    "SELECT brands, names 
       FROM tableName 
      WHERE categories LIKE '".$_GET['category']."' 
        AND (brands LIKE '".$_GET['keyword']."' 
             OR names LIKE '".$_GET['keyword']."');";
    

    Unless you are expecting there to be variations e.g. several words with the same beginning, using LIKE doesn’t achieve much. If you are expecting this, you need to use wildcards to specify where you expect the variance to be e.g.

    brands LIKE '".$_GET['keyword']."%' 
    // User enters 'Mc', SQL end up as:
    brands LIKE 'Mc%'
    // Columns matched: 'McDonalds' 'McHenry'
    

    More examples here.

    If you don’t want to allow for this, just use = instead of LIKE.

    You also need to sanitise these variables first using a regular expression or similar, as this would currently allow someone to attack your server with SQL injection.

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

Sidebar

Related Questions

I am trying to create a table in MySql using php. My code looks
I'm trying to create a mysql table from the inner join between two other
I am trying to create this table in a MySQL database CREATE TABLE IF
Im trying to create a iPhone Objective C login page using PHP/MySQL to authenticate.
I'm trying to create pagination for search results using MySQL and ColdFusion. My intention
I'm trying to convert my MySQL create table statements to SQLite create table statements.
I'm trying to execute this simple command: create table foo (clo int primary key
I'm trying to dynamically create tables in MySQL , using CodeIgniter PHP framework: if($colname
I trying to create a MySql Query from the $_POST values trouble is i
Im trying to create relationships between four tables in MySql: mainnodes (ID) subnodes (ID)

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.