-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.php
118 lines (106 loc) Β· 5.26 KB
/
login.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
session_start();
$errorMessage = '';
// Database credentials
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "login";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
if (isset($_POST['submit'])) {
$username = trim($_POST['username']);
$password = trim($_POST['password']);
// Prepare and execute the query
$stmt = $conn->prepare("SELECT * FROM login_details WHERE username = ? AND password = ?");
$stmt->bind_param("ss", $username, $password);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows == 1) {
$user = $result->fetch_assoc();
$role = $user['role'];
// Set session variables
$_SESSION['username'] = $username;
$_SESSION['role'] = $role;
// Redirect to the appropriate dashboard
if ($role == 'Admin') {
header('Location: admin_dashboard.php');
exit();
} elseif ($role == 'Employee') {
header('Location: employee_dashboard.php');
exit();
} elseif ($role == 'Customer') {
header('Location: customer_dashboard.php');
exit();
} else {
echo "Invalid role";
exit();
}
} else {
$errorMessage="Invalid username or password";
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
<title>Login - Brand</title>
<link rel="stylesheet" href="assets/bootstrap.min.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Nunito:200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i&display=swap">
</head>
<body class="bg-gradient-primary" style="background: #eb8d4a;">
<div class="container">
<div class="row justify-content-center">
<div class="col-md-9 col-lg-12 col-xl-10">
<div class="card shadow-lg o-hidden border-0 my-5">
<div class="card-body p-0">
<div class="row">
<div class="col-lg-6 d-none d-lg-flex">
<div class="flex-grow-1 bg-login-image" style="background: url("assets/img/dogs/thiru_excavatorbeautifulcolorfulasethatic8krealisticwallpaperno_229741c3-2fee-432e-80a7-7eb9d54c5b5d.png") center / cover;"></div>
</div>
<div class="col-lg-6" style="height: 518.025px;">
<div class="p-5" style="height: 518.65px;">
<div class="text-center">
<h4 class="text-dark mb-4" style="margin-bottom: 40px;">Welcome Back!</h4>
</div>
<form class="user" action="" method="post" style="height: 298.6px;">
<div class="mb-3">
<input class="form-control form-control-user" type="text" placeholder="Username" name="username" required="" style="margin-bottom: 20px;margin-top: 71px;font-size: 15px;">
</div>
<div class="mb-3">
<input class="form-control form-control-user" type="password" placeholder="Password" name="password" style="margin-bottom: 20px;font-size: 15px;">
</div>
<!-- <button class="btn btn-primary d-block btn-user w-100" type="submit" style="background: #782c25;margin-bottom: 60px;font-size: 15px;">Login</button> -->
<input class="btn btn-primary d-block btn-user w-100" type="submit" name="submit" value="Login" class="button" style="background: #782c25;margin-bottom: 60px;font-size: 15px;">
<hr>
<div style="text-align: center;">
<a class="small" href="forgot_password.php" style="font-size: 15px;color: #782c25;">Forgot Password?</a>
</div>
<div style="text-align: center;"><a class="small" href="account.php" style="font-size: 15px;color: #782c25;">Create an Account!</a></div>
</form>
<?php
if (!empty($errorMessage)) {
echo '<div class="alert alert-danger">' . $errorMessage . '</div>';
}
?>
<div class="text-center"></div>
<div class="text-center" style="padding-bottom: 0px;"></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="assets/bootstrap.min.js"></script>
<script src="assets/bs-init.js"></script>
<script src="assets/theme.js"></script>
</body>
</html>