Jump to content

Removing slashes from mysql_real_escape_string


Canman2005

Recommended Posts

Hi all

 

I'm doing some insert queries in PHP and I am using the followng to make the data being inserted SAFE

 

$full_nane = mysql_real_escape_string($_POST['full_name']);

 

I asume this is correct.

 

But in the database it's outputting for example

 

David\\\'s

 

So it's added 3 slashes, which I believe is right.

 

The problem comes when I output it, the 3 slashes remain, I have tried

 

stripslashes

 

but it just removes 2 of the 3 slashes

 

Any ideas?

Link to comment
Share on other sites

This is because you have magic quotes enabled on your server I think. Use this instead:

 

<?PHP 
// Fix a $_POST variable called variable for MySQL 
$variable = $_POST['variable']; 
if (get_magic_quotes_gpc()) 
{ 
  // If magic quotes is enabled - turn the string back into an unsafe string 
  $variable = stripslashes($variable); 
} 

// Now convert the unsafe string into a MySQL safe string 
$variable= mysql_real_escape_string($variable); 

// $variable should now be safe to insert into a query 
?>

Link to comment
Share on other sites

Yep, tried it with new data, doesnt seem to work

 

I was told to declare mysql_real_escape_string to all variables when I insert them, to avoid any hacking of the database, so now I have tons of data with slashes in it.

 

If it's common practise to use declare mysql_real_escape_string when dealing with INSERTS & UPDATES, then how do people normally remove the slashes when viewing the data through a PHP page

Link to comment
Share on other sites

It should remove it by itself when retrieving.  Are you using addslashes() as well?

Are you sure you are checking to see if get_magic_quotes_gpc() and then running stripslashes() ?  Your data is being escaped more than once or you wouldn't have "David\\\'s"

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.