<?php
session_start();
$message ="";
$connect = mysqli_connect("localhost", "root","", "testdb");
if(isset($_POST['login']))
{
if(empty($_POST["email"]) && empty($_POST["password"]))
{
echo '<script>alert("Both Fields are required")</script>';
}
else
{
$uemail = mysqli_real_escape_string($connect, $_POST["email"]);
$upassword = mysqli_real_escape_string($connect, $_POST["password"]);
$upassword = md5($upassword);
$query = "SELECT * FROM users1 WHERE email = '$uemail' AND password = '$upassword'";
$result = mysqli_query($connect, $query);
$count=mysql_num_rows($result) ;
if($count=1)
{
$role= mysql_fetch_array($result);
if($role == "admin")
{
header("location: index2.php");
exit();
}
elseif($role == "user")
{
header("location: index3.php");
exit();
}
}
else
{
echo "wrong email and password";
}
}
} ?>
我正在尝试根据角色将login.php重定向到不同的页面。
我有enum的角色,即&#39; admin&#39;,&#39;用户&#39;不幸的是我收到了这个错误..我甚至检查了$ query。
它没有语法错误..但它无法将数据提取到$ role。
警告:mysql_num_rows()期望参数1是资源,第20行/Applications/XAMPP/xamppfiles/htdocs/p51/login.php中给出的对象错误的电子邮件和密码