But mysql_real_escape_string() and handling magic qoutes are two different kind of tasks, but they are in a relation in a point of view.
the logic is this:
if magic qoutes is active, run stripslashes on the user input when its posted.
If magic qoutes set OFF, you should not apply stripslashes.
If you add the user inputs into an SQL string, you should apply mysql_real_escape_string() to filter user inserted SQL injections.
This little example follows this logic:
function mres( $string ) {
if(get_magic_quotes_gpc())
$string= stripslashes($string);
return mysql_real_escape_string($string);
}