nathanblogs Posted November 8, 2007 Share Posted November 8, 2007 Hey I am having trouble matching a field that contains \'. For example say the companies table there was a value of "exam\'ple" as the company_name. If I use the following: $data[0] = "exam\'ple"; $qry = 'SELECT * FROM companies WHERE company_name LIKE "' . $data[0] .'"'; then run the query it will return an empty set result, even though they are exactly the same. I have tried using '' instead of "" but occur the same problem. Quote Link to comment Share on other sites More sharing options...
trq Posted November 8, 2007 Share Posted November 8, 2007 Do you actually have the slashes stored within your database? You shouldn't. Quote Link to comment Share on other sites More sharing options...
nathanblogs Posted November 8, 2007 Author Share Posted November 8, 2007 Yes, someone else put them there :/ Quote Link to comment Share on other sites More sharing options...
nathanblogs Posted November 8, 2007 Author Share Posted November 8, 2007 you need to escape the characters to do so i made a regex to replace \' with \\\\' $data[0] = ereg_replace("\'","\\\\\'",$data[0]); the reason there is slashes there in the first place is to stop sql injection. edit: missed a \ 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.