在我的作业中,我有两类用户——学生和讲师。我的数据库中有一个包含用户名、密码和角色的表。(0=学生,1=讲师)登录系统运行良好,但我需要他们根据角色将其重定向到不同的页面。
<?php
include("connect.php");
if(isset($_POST['submit'])) {
$username = $_POST['username'];
$password = $_POST['password'];
$query = mysqli_query($conn, "select * from student_login where id_num ='$username' AND s_pass='$password'");
$rows = mysqli_num_rows($query);
if ($rows == 1){
$row=mysqli_fetch_array($query);
session_start();
$_SESSION['loggedin'] = true;
$_SESSION['username'] = $username;
$_SESSION['role'] = '0';
header("location: index.php");
}
elseif ($rows==1) {
{
session_start();
$_SESSION['loggedin'] = true;
$_SESSION['username'] = $username;
$_SESSION['role'] = '1';
header("location: lecturermain.php");
}
}
else{
header ("location: login.php?login_err='Can't login'");
}
$mysqli_close($conn);
}
?>
它似乎不起作用,因为每当我试图登录讲师,它会重定向到学生的页面。我应该把
$_SESSION['role'] = '1';
和
$_SESSION['role'] = '0';
在其他地方而不是login_act.php?
x
姓名和
y
十
和
当这个学生登录时,而不是
a
和
b
另一个学生?
如有任何帮助和解释,将不胜感激。提前谢谢!