tjverge Posted February 21, 2013 Share Posted February 21, 2013 (edited) Hello, I have data in an My SQL database that has an apostrophe in it eg: TJ's right now I have the following code $namesearch = mysql_real_escape_string($_POST['name']); $query = "SELECT * FROM pilot WHERE name='$namesearch' "; $result = mysql_query($query) or die(mysql_error()); if (mysql_num_rows($result) ) { include 'show.php'; } else { } It does not come back finding any thing and if I echo $namesearch I get TJ\\\'s How do I get it to search for TJ's rather then TJ\\\'s? Edited February 21, 2013 by tjverge Quote Link to comment https://forums.phpfreaks.com/topic/274784-apostrophe-in-db/ Share on other sites More sharing options...
Jessica Posted February 21, 2013 Share Posted February 21, 2013 You NEED the escape in there, so that it doesn't break your SQL statement. Try using LIKE('%$str%') instead. If the name isn't EXACTLY the same = won't match it. Quote Link to comment https://forums.phpfreaks.com/topic/274784-apostrophe-in-db/#findComment-1413943 Share on other sites More sharing options...
tjverge Posted February 21, 2013 Author Share Posted February 21, 2013 You NEED the escape in there, so that it doesn't break your SQL statement. Try using LIKE('%$str%') instead. If the name isn't EXACTLY the same = won't match it. I thought mysql_real_escape_string did escape it Quote Link to comment https://forums.phpfreaks.com/topic/274784-apostrophe-in-db/#findComment-1413944 Share on other sites More sharing options...
Jessica Posted February 21, 2013 Share Posted February 21, 2013 (edited) It DID. That's why there's a \ in it. Edited February 21, 2013 by Jessica Quote Link to comment https://forums.phpfreaks.com/topic/274784-apostrophe-in-db/#findComment-1413945 Share on other sites More sharing options...
tjverge Posted February 21, 2013 Author Share Posted February 21, 2013 It DID. That's why there's a \ in it. Thought so, so how do I get it to search TJ's insteed of TJ\s I know that if I stripslashes it will give an error Quote Link to comment https://forums.phpfreaks.com/topic/274784-apostrophe-in-db/#findComment-1413946 Share on other sites More sharing options...
Jessica Posted February 21, 2013 Share Posted February 21, 2013 It IS SEARCHING FOR TJ'S. Jesus Christ. Quote Link to comment https://forums.phpfreaks.com/topic/274784-apostrophe-in-db/#findComment-1413947 Share on other sites More sharing options...
tjverge Posted February 21, 2013 Author Share Posted February 21, 2013 It IS SEARCHING FOR TJ'S. Jesus Christ. I know what it should be doing. I would not be asking for help if it was working right I'm closing this thread as you are not being at all helpful and being kind of on the rude side, I understand you think your helping, but in this case I don't believe you understand the problem. Thank you for trying. Quote Link to comment https://forums.phpfreaks.com/topic/274784-apostrophe-in-db/#findComment-1413948 Share on other sites More sharing options...
Jessica Posted February 21, 2013 Share Posted February 21, 2013 You haven't given us enough information to help you. And you definitely don't understand how escaping certain characters works. You MUST have a \ in front of a quote in order to submit that quote within a string. That's what escape_string DOES. It adds the slashes. (It does some other stuff too). When you send it to SQL, it knows you mean "TJ's" because the \ ESCAPES the ' so it can see it as INSIDE the string, not ENDING the string. I suggested a solution, and you didn't bother to try it or tell us you did, you haven't told us WHY you think it's not working, you haven't shown any data or error messages. Why would anyone be able to solve your problem when as far as you've stated it THERE IS NO PROBLEM. Quote Link to comment https://forums.phpfreaks.com/topic/274784-apostrophe-in-db/#findComment-1413954 Share on other sites More sharing options...
tjverge Posted February 21, 2013 Author Share Posted February 21, 2013 This problem was solved it had nothing to do with the code, was a problem on the server. Quote Link to comment https://forums.phpfreaks.com/topic/274784-apostrophe-in-db/#findComment-1413955 Share on other sites More sharing options...
Jessica Posted February 21, 2013 Share Posted February 21, 2013 Maybe if you hadn't added the extra slashes to your first post, I could have seen the actual problem. When you posted it, you posted with one slash, then added the others later. No wonder. You need to turn off magic quotes. Quote Link to comment https://forums.phpfreaks.com/topic/274784-apostrophe-in-db/#findComment-1413956 Share on other sites More sharing options...
AyKay47 Posted February 21, 2013 Share Posted February 21, 2013 (edited) It seems to me like the $_POST value is being escaped twice. Use get_magic_quotes_gpc to retrieve the value of the magic_quotes_gpc option in the master php.ini file. If it returns a 1, it should be disabled. Edit: seems like I took too long with my response, glad you solved the problem. Edited February 21, 2013 by AyKay47 Quote Link to comment https://forums.phpfreaks.com/topic/274784-apostrophe-in-db/#findComment-1413957 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.