我正在创建一个Web系统,但是从用户表中登录用户时出错。
警告:mysqli_fetch_array()期望参数1为mysqli_result, 在第13行的D:\ xampp ...... \ includes \ login_inc.php中给出的布尔值。
index.php
<form id="main-form" action="includes/login_inc.php" method="post">
<p id="p-login">Please Log in to use the CRM.</p>
<label for="user">Email</label>
<input id="username" type="text" name="username" placeholder="Username">
<label for="password">Password</label>
<input id="password" type="password" name="password" placeholder="Password">
<button type="submit" name="login">Log in</button>
<p id="signup-txt">Don't have an account??.<a href="signup.php">Sign Up</a> here.
</form>
login_inc.php
<?php
require 'dbconnect.php';
session_start();
if($_SERVER["REQUEST_METHOD"] == "POST") {
$myusername = mysqli_real_escape_string($conn,$_POST['username']);
$mypassword = mysqli_real_escape_string($conn,$_POST['password']);
$sql = "SELECT id FROM users WHERE username = '$myusername' and passcode = '$mypassword';";
$result = mysqli_query($conn,$sql);
$row = mysqli_fetch_array($result,MYSQLI_ASSOC);
$active = $row['active'];
$count = mysqli_num_rows($result);
if($count == 1) {
session_register("myusername");
$_SESSION['login_user'] = $myusername;
header("location: welcome.php");
}else {
$error = "Your Login Name or Password is invalid";
}
}
?>