php如图所示 请问下 mysqli_fetch_array() 这个报错怎么解决?


<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>
<body>
 <?php
include( "conn.php" );
$username =@ $_POST['username'];
$password =@ $_POST['password'];
CLASS chkinput {
    var $name;
    var $pwd;
    function __construct( $x, $y ) {
        $this->name = $x;
        $this->pwd = $y;
    }
    function checkinput() {
        include( "conn.php" );
        $sql = mysqli_query( $conn, " select * from member where username = ' ".$this->name." ' " );
        $info = mysqli_fetch_array( $sql );
        if ( $info == false ) {
            echo "<script> alert ('不存在此用户!') ; hisrory.back() ;</script>" ;
            exit; 
        } else {
            if ( $info[ 'authority' ] == 1 ) {
                echo "<script> alert ('该用户已经冻结!') ; hisrory.back() ;</script>" ;
                exit;
            }
            if ( $info[ 'password' ] == $this->pwd ) {
                session_start();
                $_SESSION[ 'username' ] = $info[ 'username' ];
                $_SESSION[ 'ID' ] = $info[ 'ID' ];
                header( "location:welcome.php" );
                exit;
            } else {
                echo "<script> alert ('密码输入错误!') ; ;</script>" ;
                header("location:loginfail.php");
                exit;
            }
        }
    }
}
 $obj = new chkinput(trim($username),trim($password));
 $obj->checkinput();
?>
</body>
</html>

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, bool given in D:\xampp\htdocs\member\chkuser.php on line 22
源码在上面 请问下这个报错怎么解决?

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>
<body>
 <?php
include( "conn.php" );
$username = isset($_POST['username'])? $_POST['username'] : null;
$password = isset($_POST['password']) ? $_POST['password'] : null;
if (!$username || !$password) {
    echo "<script> alert ('用户名或密码不能为空!') ; hisrory.back() ;</script>" ;
    exit; 
}

CLASS chkinput {
    public $name;
    public $pwd;
    public function __construct( $x, $y ) {
        $this->name = $x;
        $this->pwd = $y;
    }
    public function checkinput() {
        // 获取 $conn 全局变量,“conn.php”中的变量
        global $conn;
        $sql = mysqli_query( $conn, " select * from member where username = ' ".$this->name." ' " );
        $info = mysqli_fetch_array( $sql );
        if ( $info == false ) {
            echo "<script> alert ('不存在此用户!') ; hisrory.back() ;</script>" ;
            exit; 
        } else {
            if ( $info[ 'authority' ] == 1 ) {
                echo "<script> alert ('该用户已经冻结!') ; hisrory.back() ;</script>" ;
                exit;
            }
            if ( $info[ 'password' ] == $this->pwd ) {
                session_start();
                $_SESSION[ 'username' ] = $info[ 'username' ];
                $_SESSION[ 'ID' ] = $info[ 'ID' ];
                header( "location:welcome.php" );
                exit;
            } else {
                echo "<script> alert ('密码输入错误!') ; ;</script>" ;
                header("location:loginfail.php");
                exit;
            }
        }
    }
}
 $obj = new chkinput(trim($username),trim($password));
 $obj->checkinput();
?>
</body>
</html>

22行改成if(empty($info))

原因找到了 两个问题导致的
其一:数据源变量名写错了 username 写成了 usernme 。改正即可:

用户名 密码 其二:数据库名称命名错了 本应该名为 member,但却用了黏贴 的 phpweb 。 改成 member 即可 总结一下这种类型的报错:这种报错,和语法无关,一定要认真检查变量名是否写错了,数据库名是否写错了。总之,追根溯源,把变量出错的地方逐一挖出来

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, bool given

这个错误,一般是
$sql = mysqli_query( $conn, " select * from member where username = ' ".$this->name." ' " );
你这个语句里面有一个参数出错的值出错,像你上面所说的 $conn 这个里面创建的对象出错了,导致出现这个错误的,又比如说 " select * from member where username = ' ".$this->name." ' " 你这个里面的表名member不存在的话,也会报错的

认真检测代码吧和变量

应该是sql语句出问题了,检查一下