错误:mysqli_fetch_array()期望参数1为mysqli_result,给出布尔值

use*_*639 -1 php mysqli

在登录时遇到这个错误,我安装了新版本的xampp/php仍然面临着很多mysqli的问题......

下面是login.php的代码,之后转到lock.php,代码如下......

<?php

include("config.php");
session_start();

if($_SERVER["REQUEST_METHOD"] == "POST")
{
// username and password sent from form 

$myusername=addslashes($_POST['username']); 
$mypassword=addslashes($_POST['password']); 


$sql="SELECT id FROM mc_admin WHERE username='$myusername' and passcode='$mypassword'";
$result=mysql_query($sql);
$row=mysql_fetch_array($result);
$active=$row['active'];

$count=mysql_num_rows($result);


// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1)
{
session_register("myusername");
$_SESSION['login_user']=$myusername;

header("location: home.php");
}
else 
{
$error="Your Login Name or Password is invalid";
}
}
?>
Run Code Online (Sandbox Code Playgroud)

以下是lock.php的代码:

<?php
include('config.php');
session_start();
$user_check=$_SESSION['login_user'];

$ses_sql=mysql_query("select username from mc_admin where username='$user_check' ");

$row=mysql_fetch_array($ses_sql);

$login_session=$row['username'];

if(!isset($login_session))
{
header("Location: login.php");
}
?>
Run Code Online (Sandbox Code Playgroud)

Nou*_*l.M 6

MYSQL查询在出错时返回FALSE,因此您的一个查询在执行时出错.

根据PHP文档mysql_query() returns a resource on success, or FALSE on error所以在尝试调用以下mysql_fetch_array检查之前:

您可以打印错误

$result = mysql_query('your query');
if (!$result) {
    die('Invalid query: ' . mysql_error());
}
Run Code Online (Sandbox Code Playgroud)

此外,您必须注意,自PHP5.5起,现在不推荐使用mysql_*函数.而不是mysql_*你可以使用mysqliPDO