Buchead Posted January 10, 2007 Share Posted January 10, 2007 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. Quote Link to comment Share on other sites More sharing options...
fenway Posted January 10, 2007 Share Posted January 10, 2007 Basically, these quotes need to be escaped, which I presume is what addslashes() does... you'd have to examine the final query going to server to check. Quote Link to comment Share on other sites More sharing options...
Buchead Posted January 11, 2007 Author Share Posted January 11, 2007 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 likeSELECT * 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. Quote Link to comment Share on other sites More sharing options...
fenway Posted January 11, 2007 Share Posted January 11, 2007 The slash IS NOT written to the DB -- it's just needed for parsing.If you're still having trouble, post some sample data. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.