gpt4 book ai didi

php - 警告 : mysqli_stmt_bind_param() expects parameter 1 to be mysqli_stmt, bool 值给出?

转载 作者:行者123 更新时间:2023-12-01 19:59:55 26 4
gpt4 key购买 nike

这是我第一次尝试使用mysqli prepared statement来保护我的代码免受sql注入(inject)。 。所以请温柔一点,用简单的语言解释一下,以便我能理解。

现在我正在使用以下代码,我认为我是对的,但它引发了这些错误,我根本不明白。

错误如下:

Warning: mysqli_stmt_bind_param() expects parameter 1 to be mysqli_stmt, boolean given in on line 92

Warning: mysqli_stmt_execute() expects parameter 1 to be mysqli_stmt, boolean given in on line 93

Warning: mysqli_stmt_close() expects parameter 1 to be mysqli_stmt, boolean given in on line 96

代码如下:

$stmt = mysqli_prepare(
$db_conx,
"INSERT $storenameTable (firstname, lastname, username, address_1, address_2, postcode, country, county, city, email, password, storeShop, signupdate) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
);
//after validation, of course
mysqli_stmt_bind_param($stmt, "issi", $firstname, $lastname, $username, $address_1, $address_2, $postcode, $country, $county, $city, $email, $hashedPass, $storenameTable);
mysqli_stmt_execute($stmt); <//<<<<<<<< line 92
if (mysqli_affected_rows($db_conx)) <//<<<<<<<< line 93
{
mysqli_stmt_close($stmt); <//<<<<<<<< line 96
//update was successful
$id = mysqli_insert_id($db_conx);
}

非常感谢您的帮助。

最佳答案

看来你缺少一个参数,你应该有13个参数和13个检查密码后的两个参数。 (我拿出了 signupdate)尝试以下操作:

$stmt = mysqli_prepare(
$db_conx,
"INSERT INTO $storenameTable (firstname, lastname, username, address_1, address_2, postcode, country, county, city, email, password, storeShop) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
);
//after validation, of course
mysqli_stmt_bind_param($stmt, "issi", $firstname, $lastname, $username, $address_1, $address_2, $postcode, $country, $county, $city, $email, $hashedPass, $storenameTable);
mysqli_stmt_execute($stmt); <//<<<<<<<< line 92
if (mysqli_affected_rows($db_conx)) <//<<<<<<<< line 93
{
mysqli_stmt_close($stmt); <//<<<<<<<< line 96
//update was successful
$id = mysqli_insert_id($db_conx);
}

您还可以使用 var_dump(mysqli_error($db_conx)); 获取有关最后一个错误的更多详细信息

关于php - 警告 : mysqli_stmt_bind_param() expects parameter 1 to be mysqli_stmt, bool 值给出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22922004/

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