调用未定义的方法mysqli_stmt :: get_results()

时间:2018-05-19 20:51:39

标签: php mysql

这是我的登录PHP代码

<?php

    session_start();

    if (isset($_POST['submit'])) {

    include 'dbh.inc.php';

    $uid = mysqli_real_escape_string($conn, $_POST['uid']);
    $pwd = mysqli_real_escape_string($conn, $_POST['pwd']);

    if (empty($uid) || empty($pwd)) {
        header("Location: ../index.php?login=empty");
        exit();
    } else {
        $sql = "SELECT * FROM users WHERE user_uid= ?";
        $stmt = $conn->prepare($sql);
        $stmt->bind_param("s",$user_uid);
        $stmt->execute();
        $result = $stmt->get_results(); //LINE 20 IS HERE BTW
        $num_rows = $result->num_rows;

        if($num_rows == 1) {

            $rows = $result->fetch_assoc();
            $hashedPwdCheck = password_verify($pwd, $row['user_pwd']);
                if ($hashedPwdCheck == false) {
                    header("Location: ../index.php?login=errorchecker");
                    exit();
                } elseif ($hashedPwdCheck == true) {
                    #Logs in
                    $_SESSION['u_id'] = $row['user_id'];
                    $_SESSION['u_first'] = $row['user_first'];
                    $_SESSION['u_last'] = $row['user_last'];
                    $_SESSION['u_email'] = $row['user_email'];
                    $_SESSION['u_uid'] = $row['user_uid'];
                    header("Location: ../index.php?login=success");
                    exit();
                }

            $read->close();
        } else {
            header("Location: ../index.php?login=errorb4pwcheck");
        }
    }
}

返回错误

  

致命错误:在第20行的C:\ wamp64 \ www \ loginsystem-1 \ includes \ login.inc.php中调用未定义的方法mysqli_stmt :: get_results()

$result = $stmt->get_results();

我已经搜索了尽可能多的线程,并且已经尝试了不同的方法来执行这个准备好的语句,我已经看到很多关于mysqlnd没有被安装和启用。 我的证明是:

phpinfo on mysqlnd

我尝试过使用bind&amp;获取方法,但它只是根本不起作用,我猜我做错了,但我看了很多不同的教程,并阅读有关它的论坛帖子,并试图将它应用到我的工作。

1 个答案:

答案 0 :(得分:0)

这是我的朋友帮助我解决的解决方案代码:)只是让任何经历过相同问题的人...     

session_start();

if (isset($_POST['submit'])) {

include 'dbh.inc.php';

$uid = $_POST['uid'];
$pwd = $_POST['pwd'];

# Error handlers
# Check if inputs are empty
if (empty($uid) || empty($pwd)) {
    header("Location: ../index.php?login=empty");
    exit();
} else {
    $sql = "SELECT * FROM users WHERE user_uid= ?";
    $stmt = $conn->prepare($sql);
    $stmt->bind_param("s", $_POST['uid']);
    $stmt->execute();
    $result = $stmt->get_result();
    $num_rows = $result->num_rows;

    if($num_rows == 1) {

        while ($rows = $result->fetch_assoc()) {
            if (!password_verify($pwd, $rows['user_pwd'])) {
                header("Location: ../index.php?login=errorchecker");
                exit();
            } else {
                #Logs in
                $_SESSION['u_id'] = $rows['user_id'];
                $_SESSION['u_first'] = $rows['user_first'];
                $_SESSION['u_last'] = $rows['user_last'];
                $_SESSION['u_email'] = $rows['user_email'];
                $_SESSION['u_uid'] = $rows['user_uid'];
                header("Location: ../index.php?login=success");
                exit();
            }
        }

        $read->close();
    } else {
        header("Location: ../index.php?login=errorb4pwcheck");
    }
}

}