tags:

views:

26

answers:

2

Hi

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.

A: 

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.

Sarfraz
If you notice the query I have posted the single quote is already escaped by adding a backslash before it. So what you are suggesting is already being done, still it's not working :(
Kunal
A: 

Hi,

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
VAC-Prabhu