$magic_quotes_active = get_magic_quotes_gpc();
$real_escape_string_exists = function_exists('mysql_real_escape_string');
function escape_value($sql) {
if ($real_escape_string_exists) {
if($magic_quotes_active) {
$sql = stripslashes($sql);
}
$sql = mysql_real_escape_string($sql);
} else {
if(!$magic_quotes_active) {
$sql = addslashes($sql);
}
}
return $sql;
}
This is considered a very secure way to insert stuff into a database. Use the returned $sql to as your query!