gpt4 book ai didi

php - 无法使用 array_shift() 获得结果

转载 作者:行者123 更新时间:2023-11-29 17:04:22 25 4
gpt4 key购买 nike

当我尝试通过 verify_user 方法验证用户数据时

<?php

public static function verify_user ($username , $password)
{
global $database;

$username = $database->escape_string($username);
$password = $database->escape_string($password);

$query = "SELECT * FROM users WHERE username = '{$username}' and password = '{$password}' LIMIT 1";

$result_array = self::find_this_query($query);

if (!empty($result_array)) {
$result_array = array_shift($result_array);

return $result_array;
} else {
return false;
}
}

这也是我的 find_this_query 方法

public static function find_this_query ($enter_here_your_sql_query)
{
global $database;

$result = $database->query($enter_here_your_sql_query);

return $result;
}

并尝试在此处登录用户以及我的login.php代码

<?php
if($session->is_signed_in()) {
redirect("index.php");
}

if (isset($_POST['submit'])) {
$username = trim($_POST['username']);
$password = trim($_POST['password']);
}

//method to check db user
$user_found = User::verify_user($username , $password);

if ($user_found) {
$session->login($user_found);

redirect("index.php");
} else {
$the_message = "<p class='alert alert-warning' style='color: grey'>Your password or username is incorrect</p>";
$username = "";
$password = "";
}
?>

我在登录页面上收到该错误

警告:array_shift() 期望参数 1 为数组,在/admin/includes/User.php 第 189 行给出的对象

这里是 user.php 类的第 189 行

$result_array = array_shift($result_array);

我在这里做错了什么?

最佳答案

$database->query() 不返回数组,而是返回一个对象。尝试使用$database->fetch_array() .

关于php - 无法使用 array_shift() 获得结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52122877/

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