What is wrong with my simple query? help

Hi,

Basically I am trying to qet a working query for Sample3 and Sample4 — they do not have the wildcard % character and use AND instead of OR.
Hope someone can help me out or point me in the right direction.

Sample1
// this works, except I dont want the wildcard % in there, I want it to match perfectly


$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
$query = "SELECT * FROM art_chk WHERE chk like '%$search_chknumber%' and code like '%$search_prdcode%' and detailed_description like '%$search_prdname%' and general_description like '%$search_description%' and art like '%$search_art%' ";
 

Sample2
// this works, except its OR and I need it to be AND as multiple things have to match


$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
$query = "SELECT * FROM art_chk WHERE chk like '$search_chknumber' OR code like '$search_prdcode' OR detailed_description like '$search_prdname' OR general_description like '$search_description' OR art like '$search_art' ";
 

Sample3
// this does not work, returns no results


$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
$query = "SELECT * FROM art_chk WHERE chk like '$search_chknumber' and code like '$search_prdcode' and detailed_description like '$search_prdname' and general_description like '$search_description' and art like '$search_art' ";
 

Sample4
//does not work, returns no results


$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
$query = "SELECT * FROM art_chk WHERE chk='$search_chknumber' and code='$search_prdcode' and detailed_description='$search_prdname' and general_description='$search_description' and art='$search_art' ";
 

Thanks

If you want it to match perfectly then use the equal operator.


SELECT * FROM art_chk
WHERE chk = '$search_chknumber'
and code = '$search_prdcode'
and detailed_description = '$search_prdname'
and general_description = '$search_description'
and art = '$search_art'

Please read up on SQL Injections: http://php.net/manual/en/security.database.sql-injection.php

I am using the = operator in sample 4 of my initial post - I even tried using your code and it returns no results, and no errors.

And, the rest of my code I am assuming is ok because when I change the query around (as in change it to sample1 or sample2 from my initial post) it works and I get the results …

Check for possible spaces in your db data and/or your variables
Also echo your query to make sure it looks like you want.
Test your query in Cpanel PHPAdmin to see what results you get

As litebearer suggested, echo $query and see if 1. that’s what you expected to see and 2. run that query in the command line/phpadmin or whatever you’re using to access mysql.