execute(); -6ren">
gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 21:43:47 25 4
gpt4 key购买 nike

这是我的登录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");
}
}
}

返回错误

Fatal error: Call to undefined method mysqli_stmt::get_results() in C:\wamp64\www\loginsystem-1\includes\login.inc.php on line 20

$result = $stmt->get_results();

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

phpinfo on mysqlnd

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

最佳答案

这是我 friend 帮我解决的解决方案代码:)以防万一有人遇到同样的问题......

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

关于php - 调用未定义的方法 mysqli_stmt::get_results(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50429387/

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