ตอนรันมันขึ้นแบบนี้อะครับ
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, object given in C:\xampp\htdocs\finalproject\login00.php on line 20
ส่วนของ code ครับ
<?php
session_start();
if (isset($_POST['username'])) {
include('database_connection.php');
$username = $_POST['username'];
$password = $_POST['password'];
$passwordenc = md5($password);
$query = "SELECT * FROM member WHERE username = '$username' AND password = '$passwordenc'";
global $conn;
$result = $conn->query($query);
if ($result->rowCount() == 1) {
global $conn;
$row = mysqli_fetch_array($result);
$_SESSION['userid'] = $row[0];
$_SESSION['user'] = $row[3];
$_SESSION['userlevel'] = $row[4];
if ($_SESSION['userlevel'] == 'a') {
header("Location: admin_page.php");
}
if ($_SESSION['userlevel'] == 'm') {
header("Location: user_page.php");
}
} else {
echo "<script>alert('User หรือ Password ไม่ถูกต้อง);</script>";
}
} else {
header("Location: index.php");
}
?>
expects parameter 1 to be mysqli_result, object given in ช่วยแก้หน่อยครับ php
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, object given in C:\xampp\htdocs\finalproject\login00.php on line 20
ส่วนของ code ครับ
<?php
session_start();
if (isset($_POST['username'])) {
include('database_connection.php');
$username = $_POST['username'];
$password = $_POST['password'];
$passwordenc = md5($password);
$query = "SELECT * FROM member WHERE username = '$username' AND password = '$passwordenc'";
global $conn;
$result = $conn->query($query);
if ($result->rowCount() == 1) {
global $conn;
$row = mysqli_fetch_array($result);
$_SESSION['userid'] = $row[0];
$_SESSION['user'] = $row[3];
$_SESSION['userlevel'] = $row[4];
if ($_SESSION['userlevel'] == 'a') {
header("Location: admin_page.php");
}
if ($_SESSION['userlevel'] == 'm') {
header("Location: user_page.php");
}
} else {
echo "<script>alert('User หรือ Password ไม่ถูกต้อง);</script>";
}
} else {
header("Location: index.php");
}
?>