Login Form Code As Category System:
Sometime you have to redirect user according to his category / position to specific page. So, here this login form code can help you. It is simple code and localhost tested.
<?php
//header('location: index.php');
//session_start();
function confirm_query($data)
{
if(!$data)
die("Query Failed: " . mysqli_connect_error());
}
$username = $_POST['username'];
$password = $_POST['password'];
$host = "localhost";
$dbuser = "root";
$dbpass = "";
$db = "estate";
$con = mysqli_connect($host, $dbuser); //Connection with server
confirm_query($con);
$connection = mysqli_select_db($con, $db); //Database is connected here
confirm_query($connection);
if(isset($_POST['submit']))
{
$query = "SELECT * FROM users where username = '{$username}' and password = '{$password}';";
$all_users = mysqli_query($con, $query);
if(!$all_users)
echo 'user pass query not working;' . mysqli_connect_error();
$user = mysqli_fetch_array($all_users);
if(mysqli_num_rows($all_users) != 0)
{
if($username == $user[username] AND $password == $user[password])
{
if($user[Category] == "Receptionist")
{
$_SESSION['username'] = $username;
header("location: receptionist.html");
exit;
}
//Example Like uncomment and change.
//make sessions and add code start_session(); in all pages start.
/*elseif($user[Category] == "Receptionist")
{
$_SESSION['username'] = $username;
header("location: receptionist.html");
exit;
}*/
}
}
}
else
{
header("location: login.html");
exit;
}
?>
Posted by
Samee Ullah Feroz
12:29 AM