我正在编写一个代码,该代码应该显示登录,注销页面,所有这些都是用PHP编写的,包括一些嵌入式HTML5和CSS。代码如下
<?php
session_start(); // Starting Session
$error=''; // Variable To Store Error Message
if (isset($_POST['submit'])) {
if (empty($_POST['username']) || empty($_POST['password'])) {
$error = "Username or Password is invalid";
}
else
{
// Define $username and $password
$username=$_POST['username'];
$password=$_POST['password'];
// Establishing Connection with Server by passing server_name, user_id and
// password as a parameter
$connection = mysqli_connect("localhost", "root", "", "Company");
// To protect MySQL injection for Security purpose
$username = stripslashes($username);
$password = stripslashes($password);
$username = mysqli_real_escape_string($connection, $username);
$password = mysqli_real_escape_string($connection, $password);
// Selecting Database
// SQL query to fetch information of registered users and finds user
//match.
$query = mysqli_query("select * from login where password='$password' AND
username='$username'", $connection);
$rows = mysqli_num_rows($query);
if ($rows == 1) {
$_SESSION['login_user']=$username; // Initializing Session
header("location: profile100.php"); // Redirecting To Other Page
} else {
$error = "Username or Password is invalid";
}
mysqli_close($connection); // Closing Connection
}
}
?>
当我在XAMPP上运行这个PHP文件时,我不断收到错误
Warning: mysqli_query() expects parameter 1 to be mysqli, string given
in C:\xampp\htdocs\FuriousCustomer1\login100.php on line 23
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result,
null given in C:\xampp\htdocs\FuriousCustomer1\login100.php on line 24
我不明白mysqli_query()如何为参数提供mysqli,或者mysqli_num_rows()如何为参数提供mysqli_result。我已经检查过,双重检查过,并且三重检查了我的代码,并参考了几本关于PHP的书籍,其中一本是Kevin Tatroe(一本非常好的书),并没有任何暗示我做错了什么,但显然我是。你们当中有人可以指出我需要做什么吗?