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. Link to comment https://forums.phpfreaks.com/topic/61706-mysql_real_escape_string-weird-problem/ 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. Link to comment https://forums.phpfreaks.com/topic/61706-mysql_real_escape_string-weird-problem/#findComment-307221 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. Link to comment https://forums.phpfreaks.com/topic/61706-mysql_real_escape_string-weird-problem/#findComment-307223 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 Link to comment https://forums.phpfreaks.com/topic/61706-mysql_real_escape_string-weird-problem/#findComment-307242 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.