Jump to content

Unable to find DB entry after using addslashes


Buchead

Recommended Posts

This is probably something obvious but I can't figure it out......

Prior to writing to the DB, I use the addslashes function. All works fine. However, when a search is entered, if the search string also has a ' in it then it doesn't find the match in the DB.

ie.  The DB has the entry:  this \'n that.

if the user types in the search string of " this 'n that " then it doesn't return a match. I've tried using the addslashes on the search string before comparing to the DB but that makes no difference. Tried using wildcards without success.

What am I doing wrong?

Thanks. 
Yes, addslashes simply adds a "\" before the ' in the column entry.

If by escaping the quotes you mean using \" then I've tried that. I've had the query so it reads:

[code]SELECT * FROM `table` WHERE `name` LIKE \"".$search."\"[/code]

with $search being the string.

I've had the output looking like

SELECT * FROM `table` WHERE `name` LIKE "%this \'n that%"
SELECT * FROM `table` WHERE `name` LIKE "%this 'n that%"
SELECT * FROM `table` WHERE `name` LIKE '%this \'n that%'

None of which actually work.

I suppose that removing the slash so it's not even written to the DB is one possibly solution, but it was also instructed to me to do that. Is this really necessary or will it not cause any problems by not having it there?

Thanks very much.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.