SharkBait Posted July 25, 2007 Share Posted July 25, 2007 I noticed that when I am using mysql_real_escape_string it seems to be adding 2 backslashes like this: <?php if(!empty($_POST['short'])) { $short = mysql_real_escape_string(trim($_POST['short'])); } else { $short = ""; } ?> So if $_POST['short'] is this: The car's paint job is great to look at becomes this when I echo it after the escape The car\\'s paint job is great to look at Now there is no other escaping of characters so i am not sure why it is doing this. Quote Link to comment Share on other sites More sharing options...
Wildbug Posted July 25, 2007 Share Posted July 25, 2007 Magic quotes is probably on. Use stripslashes before using mysql_real_escape_string -- actually do that conditionally, only if get_magic_quotes_gpc() is true. Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 25, 2007 Share Posted July 25, 2007 Are you sure you are getting two backslashes? I would expect you to either get one or three. If magic_quotes is on, i would expect 3. That is because with the setting, the string becomes: The car\'s paint job is great to look at Before you've done anything. Then, when you apply the mysql_real_escape_string() function, it escapes both the single quote and the backslash, resulting in 3 backslashes: The car\\\'s paint job is great to look at Without magic_quotes, you should just get the 1 backslash. The function should just escape the single quote. Quote Link to comment Share on other sites More sharing options...
SharkBait Posted July 25, 2007 Author Share Posted July 25, 2007 Oh yea.. that's it magic_quotes was on I wish they would make that default being off. Thanks 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.