此代码应该确保干净的代码进入数据库
它应该适用于早期版本的 PHP(早于 4.3.0)和更高版本的 php(早于 4.3.0)
它运行良好,因为数据可以毫无问题地进入数据库,但我在浏览器上遇到错误
$menu_name = mysql_prep($_POST['menu_name']);
是我如何调用 mysql_prep 函数
function mysql_prep($value)
{
$get_magic_quotes = get_magic_quotes_gpc();
$new_enough_php = function_exists ("mysql_real_escape_string"); //check if php version is greater than 4.3.0
if($new_enough_php) // if php is of a newer version
{
//undo magic quotes effect so that mysql_real_escape_string can work well
if ($get_magic_quotes)
{
$value = stripslashes ($value);
}
$value = mysql_real_escape_string($value);
}
else //mysql is older than 4.3.0
{
//add slashes manually if magic quotes are off
if(!$get_magic_quotes)
{
$value = addslashes ($value);
}
//if magic quotes already exist, slashes already exists
}
return $value;
//$value = mysql_real_escape_string($value);
//$value_without_slashes = stripslashes ($value);
//return $value_without_slashes;
}