不断收到错误:以管理员身份登录时管理员登录(管理员表单)。客户还没有表(db_table_customers)。
编辑:使用 Wamp 它给了我这个
( ! ) Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\wamp\www\dev6\login.php on line 36
Call Stack
# Time Memory Function Location
1 0.0003 692264 {main}( ) ..\login.php:0
2 0.0121 710400 mysqli_num_rows ( ) ..\login.php:36
第 36 行是$rows = mysqli_num_rows($result);
此外,var_dump()ing $result 和 $row 分别在 Web 浏览器中打印以下内容:
布尔假
无效的
这应该意味着 login.php 与我的 db_table_admins 表中为 admin 提供的登录名不匹配。但我正在为管理员提供正确的登录信息。检查了多次。
形式
<form name="admin_login" method="POST" action="login.php">
<h3>Admin:</h3>
Username: <input type="text" id="username" name="admin_login[username]"><br>
Password: <input type="password" id="password" name="admin_login[password]"><br>
<input type="submit" name="admin_submit" value="Login">
</form>
<form name="customer_login" method="POST" action="login.php">
<h3>Customer:</h3>
Username: <input type="text" id="username" name="customer_login[username]"><br>
Password: <input type="password" id="password" name="customer_login[password]"><br>
<input type="submit" name="customer_submit" value="Login">
</form>
登录.php
<?php
require('connection.inc.php');
$username = null;
$password = null;
$administrator = false;
$result = null;
$link = mysqli_connect($db_host, $db_username, $db_password, $db_database) or die("Can't connect");
if(isset($_POST['admin_submit'])){
$administrator = true;
$username = $_POST['admin_login']['username'];
$passname = $_POST['admin_login']['password'];
}else{
$username = $_POST['customer_login']['username'];
$passname = $_POST['customer_login']['password'];
}
if($administrator){
$query = "SELECT * FROM $db_table_admins WHERE username='$username' AND password='$password'";
$result = mysqli_query($link, $query);
$rows = mysqli_num_rows($result);
if($rows == 1){
$_SESSION['admin'] = true;
header("location:login_success.php");
}else{
echo "Error: admin login";
}
}else{
$query = "SELECT * FROM $db_table_customers WHERE username='$username' AND password='$password'";
$result = mysqli_query($link, $query);
$rows = mysqli_num_rows($result);
if($rows == 1){
$_SESSION['admin'] = false;
header("location:login_success.php");
}else{
echo "Error: customer login";
}
}
?>