AsiaDIT 2022-01-25 20:18 采纳率: 42.9%
浏览 69
已结题

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
源码在上面 请问下这个报错怎么解决?

  • 写回答

6条回答 默认 最新

  • 小博士不知 2022-01-25 21:23
    关注
    获得0.10元问题酬金
    <!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>
    
    评论

报告相同问题?

问题事件

  • 系统已结题 2月2日
  • 创建了问题 1月25日

悬赏问题

  • ¥15 为什么eclipse不能再下载了?
  • ¥15 编辑cmake lists 明明写了project项目名,但是还是报错怎么回事
  • ¥15 关于#计算机视觉#的问题:求一份高质量桥梁多病害数据集
  • ¥15 特定网页无法访问,已排除网页问题
  • ¥50 如何将脑的图像投影到颅骨上
  • ¥15 提问一个关于vscode相关的环境配置问题,就是输入中文但是显示不出来,代码在idea可以显示中文,但在vscode不行,不知道怎么配置环境
  • ¥15 netcore使用PuppeteerSharp截图
  • ¥20 这张图页头,页脚具体代码该怎么写?
  • ¥20 WPF MVVM模式 handycontrol 框架, hc:SearchBar 控件 Text="{Binding NavMenusKeyWords}" 绑定取不到值
  • ¥15 需要手写数字信号处理Dsp三个简单题 不用太复杂