gpt4 book ai didi

php - 如何根据某些条件重定向主页: PHP?

转载 作者:行者123 更新时间:2023-11-29 22:54:45 25 4
gpt4 key购买 nike

我想根据用户类型将我的页面重定向到不同的页面。下面是我的代码,它不起作用。需要修复它的帮助。

$check = mysql_query("SELECT * FROM user WHERE username = '".$_POST['username']."'");
$row = mysql_fetch_array($check);
switch($row["userType"])
{
case "Coordinator":
header("Location: staff_dashboard.php");
die();
break;
case "Lecturer":
header("Location: staff_dashboard.php");
die();
break;
case "Student":
header("Location: student_dashboard.php");
die();
break;
}

最佳答案

这可能对您有帮助:-

$con=mysqli_connect("localhost","my_user","my_password","my_db");
$sql="SELECT * FROM user WHERE username = '".$_POST['username']."'";
$result=mysqli_query($con,$sql);

$row=mysqli_fetch_assoc($result);

switch($row["userType"])
{
case "Coordinator":
header("Location: staff_dashboard.php");
die();
break;
case "Lecturer":
header("Location: staff_dashboard.php");
die();
break;
case "Student":
header("Location: student_dashboard.php");
die();
break;
}

关于php - 如何根据某些条件重定向主页: PHP?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28758574/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com