I have a table with the following structure:
id int(11), name varchar(250)
I have lots of records in the table but when I am trying to find a particluar record which has the following value on the name field: Lorem ipsum d\'olor sit amet The query is simply returning a blank recordset. I am not being able to figure out this weird behaviour, when my query is as simple as follows:
SELECT * FROM
slot_games
WHERE name
='Lorem ipsum d\'olor sit amet'
Would appreciate your help please! Thanks in advance.
Use the mysql_real_escape_string
(or addslashes
) function before the name
field.
Example:
$name = "Lorem ipsum d'olor sit amet";
"SELECT * FROM slot_games WHERE name='$name'";
This will basically escape the '
character and that's probably why you have the problem.
There are two ways to fix this issue
1. use mysql_real_escape_string(); // used in the Query 2. addslashes(); // used in php before query execution