我正在嘗試開發的網站中使用登錄模塊,實際上它不是典型的登錄模塊。在我的登錄表單中,如果您是什麼類型的用戶,可以選擇一個下拉框。在那裏顯示「教職員工」,「部門負責人」和「主管」。每個用戶都有不同的主頁。這裏是我的login.php
代碼:根據用戶類型在不同頁面上重定向的登錄
<?php
session_start(); // Starting Session
$error=''; // Variable To Store Error Message
if (isset($_POST['login'])) {
if (empty($_POST['username']) || empty($_POST['password'])) {
$error = "Username or Password is invalid";
}else{
// Define $username and $password
//$user_type=$_POST['user_type'];
$username=$_POST['username'];
$password=$_POST['password'];
// Establishing Connection with Server by passing server_name, user_id and password as a parameter
$connection = mysql_connect("localhost", "root", "");
// To protect MySQL injection for Security purpose
//$user_type = stripcslashes($user_type);
$username = stripslashes($username);
$password = stripslashes($password);
//$user_type = mysql_escape_string($user_type);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
// Selecting Database
$db = mysql_select_db("cpecs", $connection);
// SQL query to fetch information of registerd users and finds user match.
$query = mysql_query("select * from tblaccounts where password='$password' AND username='$username'", $connection);
$rows = mysql_num_rows($query);
if ($rows == 1) {
$_SESSION['login_user']=$username; // Initializing Session
if ($_POST['user_type']= Faculty) {
header("location: userhome.php"); //Redirecting to Faculty Home Page
}else if ($_POST['user_type']= Department) {
header("location: adminhome.php"); //Redirecting to Department Head Home Page
}else if ($_POST['user_type']= Supervisor) {
header("location: supervisorhome.php"); // Redirecting to Supervisor Home Page
}else{
$error = "Oops! It seems that you are not an authorized user.";
}
}
mysql_close($connection); // Closing Connection
}
}
?>
我也只是叫usertype
從tbluser_type
我的數據庫中的值,顯示它在下拉框中。這裏是我的代碼
<?php
include('connection.php');
$sql = "SELECT * FROM tbluser_type";
$result = mysqli_query($conn, $sql);
$option_usertype="";
while($row = mysqli_fetch_array($result)){
$option_usertype= $option_usertype."<option> $row[1] </option>";
}
?>
$ option_usertype = 「」; while $($ row = mysqli_fetch_array($ result)){ $ option_usertype。=「」; } –
請檢查我的答案 –