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. 
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.