警告:mysqli_stmt_bind_param()期望参数1为mysqli_stmt。我该如何解决呢

时间:2017-08-19 08:22:14

标签: php

我的PHP代码:

<?php
    require("password.php");

    $connect = mysqli_connect(...);

    //connect to the database 
   //  include 'finance_connection.php';

    $username = $_POST["username"];
    $password = $_POST["password"];

    $statement = mysqli_prepare($connect, "SELECT * FROM user WHERE username = ?");
    mysqli_stmt_bind_param($statement, "s", $username);
    mysqli_stmt_execute($statement);
    mysqli_stmt_store_result($statement);
    mysqli_stmt_bind_result($statement, $colUserID, $colName, $colUsername, $colAge, $colPassword, $colEmail);

    $response = array();
    $response["success"] = false;  

    while(mysqli_stmt_fetch($statement)){
        if (password_verify($password, $colPassword)) {
            $response["success"] = true;  
            $response["name"] = $colName;
            $response["age"] = $colAge;
            $response["email"] = $colEmail;
        }
    }

    echo json_encode($response);
?>

错误

Warning: mysqli_stmt_bind_param() expects parameter 1 to be mysqli_stmt, boolean given in /storage/ssd4/966/2373966/public_html/Login2.php on line 13

Warning: mysqli_stmt_execute() expects parameter 1 to be mysqli_stmt, boolean given in /storage/ssd4/966/2373966/public_html/Login2.php on line 14

Warning: mysqli_stmt_store_result() expects parameter 1 to be mysqli_stmt, boolean given in /storage/ssd4/966/2373966/public_html/Login2.php on line 15

Warning: mysqli_stmt_bind_result() expects parameter 1 to be mysqli_stmt, boolean given in /storage/ssd4/966/2373966/public_html/Login2.php on line 16

Warning: mysqli_stmt_fetch() expects parameter 1 to be mysqli_stmt, boolean given in /storage/ssd4/966/2373966/public_html/Login2.php on line 21

mysqli_stmt_bind_param($ statement,&#34; s&#34;,$ username); mysqli_stmt_execute($语句); mysqli_stmt_store_result($语句); mysqli_stmt_bind_result($ statement,$ colUserID,$ colName,$ colUsername,$ colAge,$ colPassword,$ colEmail);

我认为这些代码行存在问题

2 个答案:

答案 0 :(得分:0)

乍一看这些应该是一样的:

$ connection = mysqli_connect(...);



$ statement = mysqli_prepare( $ connect ,“SELECT * FROM user WHERE username =?”);

答案 1 :(得分:0)

1st:您的连接对象变量名称为$connection,但在查询中您使用了$connect。因此mysqli_prepare将返回布尔值false,这就是您收到这些错误的原因。

$statement = mysqli_prepare($connection , "SELECT * FROM user WHERE username = ?");