Searching for names in mySQL that contain slashes from mysql_real_escape_string()
In my users table I have a first and last name field.
I also have a search for user by last name but when there is a user like L'Orange searching for
- lor
- LOr
- L'O
- l'o
does not work while
- L\'O does (which makes sense but not something a user would think of)
So, how can my query account for that? Right now in my query I have
OR (CONCAT(`lName`, ', ', `fName`) LIKE '$term')
I'd like the search开发者_如何学Python lo or l'o to work (I think) Is there any reason the search should require the '?
How about you take the incoming search term and apply mysql_real_escape_string to it?
$term = mysql_real_escape_string($term);
then
OR (CONCAT(`lName`, ', ', `fName`) LIKE '$term')
should work. The user will have to search for l'o or L'O, but that should work.
精彩评论