0
**此代码使成功登录的用户可以被定向到student_profile.php页面,但是我需要这个来检查尝试登录的用户的类型,并根据以将该成员发送到适当的位置。在DB中,我有一个叫做account的字段,它具有不同的成员类型;学生,房东和管理员,他们都有自己的网页。 **如果else或开关的情况下从登录页面的不同位置为不同的成员组
<?php
include ("connect.php");
if (isset($_POST["user_login"]) && isset ($_POST["user_pass"])){
// formatting field via reg replace to ensure email and password only conisists of letters and numbers preg_replace('#[^A-Za-z0-9]#i','',
$login_user = $_POST["user_login"];
$login_password = $_POST["user_pass"];
// password is encryted in DB (MD5) therefore user inputted password will not match encryted password in DB - we have to assign new var
$decrypted_password = md5($login_password);
// Query which finds user (if valid) from DB - Achieving authentication via username and password
$user_query = mysqli_query($connect, "SELECT * FROM users WHERE email = '$login_user' AND password = '$decrypted_password' AND closed = 'no' LIMIT 1");
$check_user = mysqli_num_rows($user_query); // checking to see if there is infact a user which those credentials in the DB
if ($check_user==1){
while ($row = mysqli_fetch_array($user_query)){
$id = $row['user_id'];
}
// if the user credentials are correct, log the user in:
$_SESSION["user_login"] = $login_user;
header("Location:profile_student.php"); // refresh page
exit;
}
else {
echo "<div class='wrong_login'>
<p> Email or password is incorrect, please try again. </p>
</div>";
}
}
?>
感谢这就是伟大的@Ravinder雷迪 –
我想这一段代码来显示一个错误,如果用户没有输入正确的电子邮件或密码。它似乎工作,但现在不工作。 –