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
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.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.