Jump to content

mysql_real_escape_string() - Weird problem


SharkBait

Recommended Posts

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

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.

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.