Page 1 of 1
Query not working as expected
Posted: Sat Sep 18, 2010 2:01 pm
by diseman
Code: Select all
$name=$_POST['affiliate_search_for_users'];
$query = "SELECT b_firstname, b_lastname, b_state, username, b_phone_m FROM contact_info WHERE affiliate = ' ".$affiliate." ' &&
b_firstname LIKE '%" . $name ."%' OR
b_lastname LIKE '%" . $name ."%' OR
b_phone_h LIKE '%" . $name ."%' OR
b_phone_m LIKE '%" . $name ."%' OR
b_phone_w LIKE '%" . $name ."%' ";
$result = mysql_query($query) or die(mysql_error());
This is a search box search. When I put a name/user in the box to search it's good, but when I put a name of a user that belongs to a different $affiliate, it pulls the record and displays it! I expressly put in there " WHERE affiliate = ' " .$affiliate. " ' , so I shouldn't be getting any records that belong to a different $affiliate.
I've even test " print $affiliate ; " and it shows me the proper result, so the correct variable is being used.
This thing has been handing me my ass for hours. Can anyone out there help a beginner?
Thanks...
Basically, I want to search an affiliate's records based on firstname, lastname, etc..., but the record MUST belong to that affiliate.
Re: Query not working as expected
Posted: Sat Sep 18, 2010 2:17 pm
by internet-solution
You need brackets.
Code: Select all
$query = "SELECT b_firstname, b_lastname, b_state, username, b_phone_m FROM contact_info WHERE affiliate = ' ".$affiliate." ' &&
(b_firstname LIKE '%" . $name ."%' OR
b_lastname LIKE '%" . $name ."%' OR
b_phone_h LIKE '%" . $name ."%' OR
b_phone_m LIKE '%" . $name ."%' OR
b_phone_w LIKE '%" . $name ."%' )";
Re: Query not working as expected
Posted: Sat Sep 18, 2010 2:24 pm
by diseman
Huh. So simple. Wish I had asked the question 3 fricken' hours ago! : )
Thanks AGAIN Internet-Solution!
Hey, if you have the time and inclination... take a look at:
viewtopic.php?f=1&t=121306
That one is stumping me too