TAGS :Viewed: 26 - Published at: a few seconds ago

[ Searching using LIKE not returning expected result ]

I am searching on MySQL database using PHP and LIKE method, everything works great except when I type some characters like #, _, & it returns all rows even that there is not any row that has any of this character on it.

Other characters like /, ", ' works great and shows just the rows that has those characters.

The follow code is the code I use to get those results.

mysql_query("SELECT * FROM articles WHERE title LIKE '%$value%'")

Answer 1

_ is a special character, representing any single character, in the same way that % represents any sequence of multiple characters

\ is an escape character, used if you want to search for a literal percent character \%, underscore \_ or slash \\ (unless NO_BACKSLASH_ESCAPES mode is enabled)


See manual for details