-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
54 lines (45 loc) · 1.67 KB
/
index.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
<?php
include 'config.php';
// Initialize the variable
$username = "";
$studentid = "";
// Validate user input
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$username = htmlspecialchars($_POST['username'], ENT_QUOTES, 'UTF-8');
$studentid = htmlspecialchars($_POST['studentid'], ENT_QUOTES, 'UTF-8');
$sql = "SELECT * FROM voter WHERE studentid = '$studentid' AND username = '$username'";
$result = $con->query($sql);
if ($result->num_rows == 1) {
$_SESSION['studentid'] = $studentid;
$_SESSION['username'] = $username;
header("Location: election.php"); // Redirect to a protected page upon successful login
exit();
} else {
$error = "Invalid studentid or username.";
}
}
?>
<!-- // HTML form for login -->
<!DOCTYPE html>
<html>
<head>
<title>Login</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="windicss flex justify-center bg-blue-200">
<h2>Login</h2>
<?php if (isset($error)) {
echo "<p>$error</p>";
} ?>
<form method="POST" action="index.php" class="mx-auto md:w-1/2">
<label for="studentid">Student ID:</label>
<input type="text" id="studentid" name="studentid" class="w-full border-2 border-gray-300 rounded px-4 py-2" required><br><br>
<label for="username">Username:</label>
<input type="password" id="username" name="username" class="w-full border-2 border-gray-300 rounded px-4 py-2" required><br><br>
<input type="submit" value="Login" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">
</form>
</body>
</html>
<?php
$con->close();
?>