gpt4 book ai didi

php - MySQL、PHP 清理发布变量的可接受方式

转载 作者:行者123 更新时间:2023-11-30 22:00:47 25 4
gpt4 key购买 nike

<分区>

在我之前的帖子之后 PHP Looping through elements and adding to Database

我又回到了绘图板,因为我害怕注入(inject)并且想要一些建议。以下是“安全的”吗:

$stmt = $conn->prepare("INSERT INTO responses (skey, rtext) VALUES (?, ?)");
$stmt->bind_param("is", $skey, $rtext);

$skey = 1;
$rtext = mysqli_real_escape_string($conn,$_POST['Q1Answer']);
if(!$stmt->execute()){trigger_error("there was an error....".$con->error, E_USER_WARNING);}

$skey = 2;
$rtext = "Hello";
if(!$stmt->execute()){trigger_error("there was an error....".$con->error, E_USER_WARNING);}

$stmt->close();
$conn->close();

我还可以调用以下函数:

function SanitizeForSQL($str)
{
if( function_exists( "mysql_real_escape_string" ) )
{
$ret_str = mysql_real_escape_string( $str );
}
else
{
$ret_str = addslashes( $str );
}
return $ret_str;
}

以上任何一项都有助于防止注入(inject)吗?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com