Ola,我最近一直在关注本教程http://www.onlinetuting.com/create-login-script-in-php/
但是我已经做到了,但必须更改一些内容才能将其连接到我正在使用的服务器上,但是现在,当我单击带有正确或不正确的电子邮件和密码的登录名时,唯一会弹出的事件说不正确的密码,并且永远不会登录到blog.php,出现此错误:
警告:mysqli_num_rows()希望参数1为mysqli_result,在/SHOME1/sessions/login.php的33行中给定的布尔值调用堆栈:0.0013 647688 1. {main}()/SHOME1/sessions/login.php:0 0.0021 652200 2. mysqli_num_rows()/SHOME1/sessions/login.php:33
如果有人了解我遇到的问题?
这是我拥有的两个文件:
index.php
<!DOCTYPE html><?php error_reporting(E_ALL|E_STRICT); ini_set('display_errors', true); session_start();?>
<html>
<head>
<title>User Login</title>
</head>
<body>
<form action="login.php" method="post">
<table width="500" align="center" bgcolor="skyblue">
<tr align="center">
<td colspan="3"><h2>User Login</h2></td>
</tr>
<tr>
<td align="right"><b>Email</b></td>
<td><input type="text" name="email" required="required"/></td>
</tr>
<tr>
<td align="right"><b>Password:</b></td>
<td><input type="password" name="pass" required="required"></td>
</tr>
<tr align="center">
<td colspan="3">
<input type="submit" name="login" value="Login"/>
</td>
</tr>
</table>
</form>
</body>
</html>
login.php
<?php
error_reporting(E_ALL|E_STRICT); ini_set('display_errors', true);
// establishing the MySQLi connection
$hostname = "localhost";
$username = "userexample";
$password = "passexample";
$database = "userdbexample_db1";
$con = new mysqli($hostname, $username, $password, $database);
if (mysqli_connect_errno())
{
echo "MySQLi Connection was not established: " . mysqli_connect_error();
}
// checking the user
if(isset($_POST['login'])){
$email = mysqli_real_escape_string($con,$_POST['email']);
$pass = mysqli_real_escape_string($con,$_POST['pass']);
$sel_user = "select * from users where user_email='$email' AND user_pass='$pass'";
$run_user = mysqli_query($con, $sel_user);
$check_user = mysqli_num_rows($run_user);
if($check_user>0){
$_SESSION['user_email']=$email;
echo "<script>window.open('blog.php','_self')</script>";
}
else {
echo "<script>alert('Email or password is not correct, try again!')</script>";
}
}
?>
提前感谢!
您的查询失败,结果对象$ run_user为空,这就是您收到此错误的原因,我将看一下您的查询或确保您设置了要传递给查询字符串的变量。