-
Notifications
You must be signed in to change notification settings - Fork 3
/
index1.php
137 lines (125 loc) · 4.49 KB
/
index1.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
session_start();
include_once('connection.php');
if (isset($_POST['login'])) {
$username = $_POST['username'];
$password = $_POST['password'];
$userType = $_POST['user_type'];
if (empty($username) && empty($password)) {
echo "<script>alert('Please Fill Username and Password'); window.location='index.php';</script>";
exit;
} elseif (empty($password)) {
echo "<script>alert('Please Fill Password'); window.location='index.php';</script>";
exit;
} elseif (empty($username)) {
echo "<script>alert('Please Fill Username'); window.location='index.php';</script>";
exit;
} else {
$table = "";
$redirectPath = "";
if ($userType == 'user') {
$table = "login_tbl";
$redirectPath = 'welcome.php';
} elseif ($userType == 'admin') {
$table = "admin_login_tbl";
$redirectPath = 'admin/welcome.php';
} elseif ($userType == 'lecturer') {
$table = "lecturers";
$redirectPath = 'Lecturer/welcome.php';
} else {
echo "<script>alert('Invalid User Type'); window.location='index.php';</script>";
exit;
}
$sql = "SELECT * FROM `$table` WHERE `username`='$username' AND `password`='$password'";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
$row = mysqli_fetch_array($result);
$name = $row['name'];
$storedUsername = $row['username'];
$storedPassword = $row['password'];
if ($username == $storedUsername && $password == $storedPassword) {
$_SESSION['name'] = $name;
$_SESSION['username'] = $username;
header('location: ' . $redirectPath);
exit;
}
} else {
echo "<script>alert('Invalid Username or Password'); window.location='index.php';</script>";
exit;
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-iYQeCzEYFbKjA/T2uDLTpkwGzCiq6soy8tYaI1GyVh/UjpbCx/TYkiZhlZB6+fzT" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css">
<style>
body {
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
background-color: #f8f9fa;
}
.login-container {
background: #fff;
padding: 2rem;
border-radius: 1rem;
box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
max-width: 600px;
width: 100%;
text-align: center;
}
.login-container h1 {
text-align: center;
margin-bottom: 2rem;
}
.login-container img {
max-width: 50%;
height: auto;
margin-bottom: 1rem;
}
.login-container .form-control {
border-radius: 25px;
}
.login-container button {
width: 100%;
border-radius: 25px;
background-color: #3333ff;
border-color: #3333ff;
color: #fff;
}
.login-container button:hover {
background-color: #1a1aff;
border-color: #1a1aff;
}
</style>
</head>
<body>
<div class="login-container">
<h1>Student Information System</h1>
<img src="pics/login.png" alt="Login Image">
<form action="" method="POST">
<div class="mb-3">
<input type="text" class="form-control" name="username" placeholder="Username" required>
</div>
<div class="mb-3">
<input type="password" class="form-control" name="password" placeholder="Password" required>
</div>
<div class="mb-3">
<select name="user_type" class="form-select" required>
<option value="user">User</option>
<option value="admin">Admin</option>
<option value="lecturer">Lecturer</option>
</select>
</div>
<button type="submit" class="btn btn-primary" name="login">Login</button>
</form>
</div>
</body>
</html>