我正在运行这段代码,并收到2条警告错误。
<?php
include_once 'connect_db.php';
if (isset($_POST['submit'])) {
$username = $_POST['username'];
$password = $_POST['password'];
$position = $_POST['position'];
switch ($position) {
case 'Admin':
$result = mysqli_query($conn, "SELECT admin_id, username FROM admin WHERE username='{$username}' AND password='{$password}'");
$row = mysqli_fetch_array($result);
if ($row > 0) {
session_start();
$_SESSION['admin_id'] = $row[0];
$_SESSION['username'] = $row[1];
header('location:http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . '/admin.php');
} else {
$message = '<font color=red>Invalid login Try Again</font>';
}
break;
}}
?>
我收到以下警告错误:
Warning: mysqli_query(): Couldn't fetch mysqli in C:\xampp\htdocs\Pharmacy\index.php on line 9
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in C:\xampp\htdocs\Pharmacy\index.php on line 10
mysqli_query参数1和mysqli_fetch_array参数有问题