警告:mysqli_stmt_bind_param()期望参数1是mysqli_stmt,给定布尔值? [重复]

问题描述 投票:1回答:2

这个问题在这里已有答案:

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

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

这是错误:

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);
}

我将非常感谢你的帮助。

php mysqli
2个回答
1
投票

看来你有一个缺失的参数,你应该有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));获取有关上一个错误的更多详细信息


0
投票

password是MySQL中的函数名。函数名称(如保留字)必须包含在反引号中以用作字段名称。

就个人而言,我会说围绕所有数据库,表和列名称添加反引号。

在MySQL中使用“裸”名称类似于在PHP中使用裸字符串。当然,$foo = bar;将起作用,但它依赖于bar不是一个常数。好吧,在MySQL中,你依赖的是你的列名而不是保留字。一样。使用反引号!

© www.soinside.com 2019 - 2024. All rights reserved.