-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.php
More file actions
105 lines (82 loc) · 2.7 KB
/
Copy pathindex.php
File metadata and controls
105 lines (82 loc) · 2.7 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
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
<?php
// Start a session
session_start();
// Database credentials
$host = "localhost";
$user = "root";
$password = "";
$dbname = "students_DB";
// Create connection
$conn = new PDO("mysql:host=$host;dbname=$dbname", $user, $password);
// Initialize the $status variable to "Enter your credentials"
$status = "Enter your credentials";
// Check if the form has been submitted
if (!empty($_POST)) {
// Get the username and password from the form
$username = $_POST['username'];
$password = $_POST['password'];
// Prepare a statement to select the user from the database
$sql = 'SELECT * FROM admin WHERE username = ?';
$stmt = $conn->prepare($sql);
// Bind the user's username to the statement parameter
$stmt->bindParam(1, $username);
// Execute the statement
$stmt->execute();
// Get the user data from the statement result
$user = $stmt->fetch(PDO::FETCH_ASSOC);
// Verify the password
if ($user && $password == $user['password']) {
// If the password is correct, log the user in
$_SESSION['username'] = $username;
header('Location: dashboard.php');
exit; // Make sure to exit here to prevent the rest of the script from executing
} else {
// If the password is incorrect, set the $status variable to "Invalid login credentials"
$status = "Invalid login credentials.";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Student Management System</title>
<link rel="icon" href="./assets/img/fav.png">
<link rel="stylesheet" href="./assets/styles/index.css">
</head>
<body>
<header>
<h1>Student Management System</h1>
</header>
<main>
<div id="login-form">
<div id="h2">
<h2>Login</h2>
</div>
<form action="index.php" method="post">
<?php
// Display the $status variable inside the login-form div
echo '<div id="login-status">' . $status . '</div>';
?>
<input type="text" name="username" placeholder="Username">
<input type="password" name="password" placeholder="Password">
<button type="submit">Login</button>
<button type="button" name="change-password" id="change-pass"
onclick="window.location.href='change_password.php'">Forgot Password</button>
<button type="reset">Cancel</button>
</form>
</div>
</main>
<footer>
<p>© All Rights Reserved 2023</p>
</footer>
</body>
</html>
<script>
// Add an event listener to the reset button
document.querySelector('button[type="reset"]').
addEventListener('click', function() {
// Clear the login status and password
document.getElementById('login-status').
textContent = 'Enter your credentials';
});
</script>