-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin.php
More file actions
46 lines (37 loc) · 1.44 KB
/
admin.php
File metadata and controls
46 lines (37 loc) · 1.44 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
<?php
session_start();
// Database connection
$conn = mysqli_connect("localhost", "root", "", "portfolio");
// Handle form submission
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$username = $_POST['username'];
$password = md5($_POST['password']); // must match how it's stored
$sql = "SELECT * FROM admin WHERE username = '$username' AND password = '$password'";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) == 1) {
// Login success
$_SESSION['admin'] = $username;
header("Location: contact_management.php");
exit();
} else {
// Login failed
$error = "Invalid username or password.";
}
}
$current_page = 'admin';
$page_title = 'Admin Login';
require 'header.php';
?>
<div class="admin-login">
<h2 class="admin-title">Admin Login</h2>
<p class="admin-desc">Login page for the owner of this website. :)</p>
<?php if (!empty($error)): ?>
<p style="color: var(--danger); font-size: 0.9rem; margin-bottom: 1rem;"><?php echo $error; ?></p>
<?php endif; ?>
<form action="admin.php" method="post" class="admin-form">
<input type="text" id="username" name="username" placeholder="Username" required>
<input type="password" id="password" name="password" placeholder="Password" required>
<button type="submit">Login</button>
</form>
</div>
<?php require 'footer.php'; ?>