我有一个基本的登录页面。我目前使用的用户表中有用户名和密码列。我的系统有3种类型的用户:校长,学术总监和讲师。事实是我为每个用户创建了表。如何检测它们并将它们引导到主页面?例如,对于讲师用户,我有2个colummns lecusername和lecpasswprd。
<html>
<head><h1>Login Page</h1>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<center>
<form action = "login.php" method = "POST">
Username: <input type="text" name="username"> <br /><br/>
Password: <input type="password" name="password"> <br /><br/>
<input type="submit" value="Login" name="submit">
</form>
</center>
</body>
</html>
<?php
$error ='';
require('connect.php');
$username = @$_POST['username'];
$password = @$_POST['password'];
if(isset($_POST['submit']))
{
if($username && $password)
{
$check = mysql_query("SELECT * FROM users WHERE username='".$username."' AND password= '".$password."'");
$rows = mysql_num_rows($check);
if(mysql_num_rows($check)!=0)
{
session_start();
header("location:/main.php");
exit();
}
else
{
echo "Couldn't find username.";
}
}
else
{
echo "Please fill all the fields.";
}
}
?>
答案 0 :(得分:1)
您的表应该有另一个列定义为userType。
Select语句应该返回该列。
$check = mysql_query("SELECT userType
FROM users
WHERE username='".$username."'
AND password= '".$password."'");
现在你应该阅读什么是userType
$rows = mysql_fetch_row($check);
if($rows[0] == "admin")
{
session_start();
header("location:/admin.php");
}