-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
53 lines (46 loc) · 1.54 KB
/
index.php
File metadata and controls
53 lines (46 loc) · 1.54 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
<?php
session_start();
include 'db.php';
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$email = mysqli_real_escape_string($conn, $_POST['email']);
$password = $_POST['password'];
$result = $conn->query("SELECT * FROM users WHERE email = '$email'");
if ($result->num_rows === 1) {
$user = $result->fetch_assoc();
if (password_verify($password, $user['password'])) {
$_SESSION['user_id'] = $user['id'];
header("Location: dashboard.php");
exit();
} else {
$error = "Invalid credentials!";
}
} else {
$error = "User not found!";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Login</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<h1 style="text-align: center;"> LOST AND FOUND PORTAL </h1>
<div class="form-container">
<form method="POST" class="form-card">
<h2>Login</h2>
<?php if (isset($error)): ?>
<p class="error-msg"><?php echo $error; ?></p>
<?php endif; ?>
<?php if (isset($_GET['success'])): ?>
<p class="success-msg">Registration successful! Please log in.</p>
<?php endif; ?>
<input type="email" name="email" placeholder="Email Address" required>
<input type="password" name="password" placeholder="Password" required>
<button type="submit">Login</button>
<p class="form-footer">Don't have an account? <a href="register.php">Register</a></p>
</form>
</div>
</body>
</html>