-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
74 lines (63 loc) · 2.55 KB
/
index.php
File metadata and controls
74 lines (63 loc) · 2.55 KB
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
<?php
include_once 'include.php';
if( isset($_POST['username']) && isset($_POST['password'])){
//echo "you";die;
$username = $_POST['username'];
$password = $_POST['password'];
//echo $username; die;
// select a particular user by id and password
$stmt = $pdo->prepare("SELECT COUNT(*) AS count FROM staffs WHERE reg_No = ? AND `password` = ?");
$stmt->execute([$username, $password]);
$staffRow = $stmt->fetch(PDO::FETCH_OBJ);
//var_dump($staffRow); die;
if($staffRow && $staffRow->count == 1){
$stmt = $pdo->prepare("SELECT `Role` FROM staffs WHERE reg_No = ? AND `password` = ?");
$stmt->execute([$username, $password]);
$staffRole = $stmt->fetch(PDO::FETCH_OBJ);
if($staffRole->Role == "Librarian"){
$_SESSION['reg_No'] = $username;
header("Location: librarian_home.php");
exit;
}else{
$_SESSION['reg_No'] = $username;
header("Location: staffs_home.php");
exit;
}
}
$stmt = $pdo->prepare("SELECT COUNT(*) AS count FROM students WHERE reg_No = ? AND `password` = ?");
$stmt->execute([$username, $password]);
$studentRow = $stmt->fetch(PDO::FETCH_OBJ);
//var_dump($studentRow->count); die;
if($studentRow && $studentRow->count == 1){
$_SESSION['studentId'] = $username;
header("Location: student_home.php");
exit;
}
else{
header("Location: index.php?incorrectLogin=1");
}
} //else echo "nothing!";
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Library</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="header">
<h1>MBEYA UNIVERSITY OF SCIENCE AND TECHNOLOGY</h1>
</div>
<form action="" method="post">
<label for="username">Username</label>
<input type="text" id="username" name="username" required>
<label for="password">Password</label>
<input type="password" id="password" name="password" required><br>
<input type="checkbox" name="" id=""> Remember Me
<a href="#">Forgot Password?</a><br>
<button type="submit">Login</button>
</form>
</body>
</html>