Jump to content

[SOLVED] mysql_real_escape_string question


dennismonsewicz

Recommended Posts

No you don't have to use strip_slashes after the use of mysql_real_escape_string.

 

However before running mysql_real_escape_string you should first run strip_slashes encase magic quotes is enabled. Forexample

 

function makeSafe($data)
{
    // undo magic_quotes
    if(get_magic_quotes_gpc())
        $data = strip_slashes($data);

    return mysql_real_escape_string($data);
}

// example usage
$myName = makeSafe($_POST['my_name_field']);

Right

 

Maybe an example will help.

 

<?php
$string = "Something's that's need's escaping";
$query = "UPDATE table SET string = '" . mysql_real_escape_string($string) . "'";
$result = mysql_query();

$query = "SELECT string FROM table";
$result = mysql_query($query);
$row = mysql_fetch_assoc($result);

echo $row['string']; // Something's that's need's escaping
?>

 

If you are using mysql_real_escape_string to build your quere

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.