以下为引用的内容: <?PHP
// Fix a _POST variable called firstName for MySQL
firstName = _POST['firstName'];
if (get_magic_quotes_gpc())
{
// If magic quotes is enabled - turn the string back into an unsafe string
firstName = stripslashes(firstName);
}
// Now convert the unsafe string into a MySQL safe string
firstName= mysql_real_escape_string(firstName);
// firstName should now be safe to insert into a query
?>
输出到页面
为正确显示字符中的引号和反斜线,应使用stripslashes()函数
以下为引用的内容: <?PHP
firstName = _POST['firstName'];
if (get_magic_quotes_gpc())
{
// If magic quotes is enabled - turn the string back into an unsafe string
firstName = stripslashes(firstName);
}
// Now convert the unsafe string into a MySQL safe string
firstName = mysql_real_escape_string(firstName);
// Safe query
mysql_query("Insert INTO Names VALUES('". firstName ."')");
以下为引用的内容: <?PHP
function VerifyInput(input, forceInt = false)
{
if (is_numeric(input))
{
return input;
}
elseif (!forceInt)
{
if (get_magic_quotes_gpc())
{
// if magic quotes is enabled, get rid of those
// pesky slashes
input = stripslashes(input);
}
// convert the input variable into a MySQL safe string.
input = mysql_real_escape_string(input);
return input;
}
else
{
// if input not an integer and forceInt = true,
// kill script
die("Invalid Input");
}
}
// _POST['name'] should be a string
// _POST['id'] should be an integer, if not the script dies
id = _POST['id'];
name = _POST['name'];