警告:mysqli_fetch_array()期望参数1为mysqli_result,在第15行的/public_html/access/login.php中给出的null [英] Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in /public_html/access/login.php on line 15

查看:159
本文介绍了警告:mysqli_fetch_array()期望参数1为mysqli_result,在第15行的/public_html/access/login.php中给出的null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经搜索了这里的每个地方,但找不到我的问题的答案.我的注册页面工作正常,但是当我尝试登录时,出现以下错误.我不完全确定该怎么做:

I've searched every where on here, and I cannot find the answer to my problem. My registering page works fine, but when I attempt to login I am given the following errors. I'm not entirely sure what to do:

警告:mysqli_fetch_array()期望参数1为mysqli_result, 第15行的public_html/access/login.php中给出的null

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in public_html/access/login.php on line 15

AND

警告:mysqli_fetch_array()期望参数1为mysqli_result,在第29行的public_html/access/login.php中给出空值

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in public_html/access/login.php on line 29

这是我的代码,我将遇到问题的行用斜体表示:

Here is my code, I've italicised the lines that I'm having problems with:

<?php
        require_once($_SERVER['DOCUMENT_ROOT'] . "/html5up-aerial/access/functions.php");
        $username = trim($_POST['username']);
        $password = trim($_POST['password']);
        if ($username&&$password) {
                session_start();
                require_once($_SERVER['DOCUMENT ROOT'] . "db_connect.php");
                mysqli_select_db($db_server, $db_database) or
                                                    die("Couldn't find db");
                $username = clean_string($db_server, $username);
                $password = clean_string($db_server, $password);

                $query = "SELECT * FROM users WHERE username='$username'";
                $result - mysqli_query($db_server, $query);
                *if($row = mysqli_fetch_array($result)){*
                   $db_username = $row['username'];
                   $db_password = $row['password'];
                   if($username==$db_username&&salt($password)==$db_password){
                      $_SESSION['username']=$username;
                      $_SESSION['logged']="logged";
                      header('Location: home.php');
                   }else{
                       $message = "<h1>Incorrect password!</h1>";
                   }
                }else{
                    $message = "<h1>That user does not exist!</h1>" . 
                                    "Please <a href='index.php'>try again</a>";
                }
                *mysqli_free_result($result);*
                require_once("db_close.php");
            }else{
                $message = "<h1>Please enter a valid username/password</h1>";
            }
            //header/footer only required if submitting to a seperate page
?>

推荐答案

您的第一个问题是您已经编写了这样的代码

Your first issue is that you have written the code like this

 $result - mysqli_query($db_server, $query);

这是不正确的,请使用下面的代码行进行更改.

This is incorrect please change with below line of code.

$result = mysqli_query($db_server, $query);

希望它会对您有所帮助.

Hope it will help you.

这篇关于警告:mysqli_fetch_array()期望参数1为mysqli_result,在第15行的/public_html/access/login.php中给出的null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆