doudou_3636
2014-04-07 20:06 浏览 176
已采纳

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

this is the first time ever that I am trying to secure my code against sql injection using mysqli prepared statement. so please be gentle and explain things in simple terms so I can understand it.

Now I am using the following code which I thought i was right but it throws these errors and I do not understand that at all.

here is the errors:

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

here is the code:

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

i would appreciate your help.

</div>
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答 默认 最新

  • 已采纳
    doz22551 doz22551 2014-04-07 20:16

    It seems that you have a missing parameter, you should have 13 parameters and 13 ? check the two parameters after password. (I took out signupdate) try the below :

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

    You also can get more details on the last error by using var_dump(mysqli_error($db_conx));

    点赞 评论 复制链接分享
  • dqwh1219 dqwh1219 2014-04-07 20:09

    password is a function name in MySQL. Function names, like reserved words, must be enclosed in backticks to be used as a field name.

    Personally, I'd say put backticks around all database, table and column names.

    Using "bare" names in MySQL is akin to using bare strings in PHP. Sure, $foo = bar; will work, but it relies on bar not being a constant. Well, in MySQL, you are relying on your column names not being reserved words. Same thing. Use backticks!

    点赞 评论 复制链接分享

相关推荐