Page 1 of 1
Is there a problem with the or operator in mysql?
Posted: Fri Jun 06, 2008 4:09 pm
by Sheridan
I am trying to execute an mysql query of the form:
Code: Select all
$query = "Select * from individuals where MotherId like '%".$iName."%' or FatherID like '%".$iName."%' ";
I am getting an "unexpected FatherID" error message. FatherID is of course an attribue of the queried table. The query works as long as I do not have the OR condidtion. That is, the following query works.
Code: Select all
$query = "Select * from individuals where MotherId like '%".$iName."%' ";
What am I doing wrong?

Re: Is there a problem with the or operator in mysql?
Posted: Fri Jun 06, 2008 4:20 pm
by Jade
Sheridan wrote:
Code: Select all
$query = "Select * from individuals where MotherId like '%".$iName."%' or FatherID like '%".$iName."%' ";
Try:
Code: Select all
$query = "Select * from individuals where MotherId like '%$iName%' or FatherID like '%$iName%'";
Only other thing I can think either $iName has weird characters in it (if so escape them first) or fatherID is for some reason a reserved keyword in mysql.
Re: Is there a problem with the or operator in mysql?
Posted: Fri Jun 06, 2008 4:39 pm
by dbemowsk
What is the exact error you are getting?
I should be able to help you further once I see the exact error.
I do see though that you have "Motherid" and "FatherID". Should the "FatherID" be "Fatherid"? That can make a difference as field names are case sensitive.
____________________________________________________
Jade, he is not incorrect in the way the query is written. He is using string concatenation which is perfectly fine. I actually prefer to do it that way versus using the variables inside the quotes because I use a syntax highlighting editor which allows me to better see where I have variables being inserted into strings. I see it like this:
$query = "Select * from individuals where MotherId like '%".$iName."%' or FatherID like '%".$iName."%' ";
versus like this
$query = "Select * from individuals where MotherId like '%$iName%' or FatherID like '%$iName%' ";