开发者

Searching for names in mySQL that contain slashes from mysql_real_escape_string()

开发者 https://www.devze.com 2023-02-05 16:26 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号