-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuser_dashboard.php
More file actions
101 lines (83 loc) · 2.87 KB
/
Copy pathuser_dashboard.php
File metadata and controls
101 lines (83 loc) · 2.87 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
<?php
session_start();
include_once('database.php');
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true || $_SESSION['isAdmin'] !== 0) {
header("Location: userlogin.html");
exit();
}
?>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="styles.css">
<style>
#user-details {
width: 80%;
margin: 20px auto;
border-collapse: collapse;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
#user-details th, #user-details td {
border: 1px solid #ddd;
padding: 12px;
text-align: left;
}
#user-details th {
background-color: #f2f2f2;
}
#user-details tr:nth-child(even) {
background-color: #f9f9f9;
}
h2 {
text-align: center;
}
a {
display: block;
text-align: center;
margin-bottom: 10px;
}
</style>
</head>
<body>
<h1>Welcome,
<?php
try {
$stmt = $conn->prepare("SELECT Username FROM User WHERE Email = :email");
$stmt->bindParam(':email', $_SESSION['email']);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
echo htmlspecialchars($row['Username'] ?? "User");
} catch (PDOException $e) {
error_log("Error fetching username: " . $e->getMessage());
echo "User";
}
?>!
</h1>
<h2 style="text-align: center;">Your Details</h2>
<table id="user-details">
<?php
try {
$stmt = $conn->prepare("SELECT BloodType, PlasmaType, CityName FROM User u JOIN City c ON u.Location = c.CityID WHERE Email = :email");
$stmt->bindParam(':email', $_SESSION['email']);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if ($row) {
foreach($row as $key => $value) {
echo "<tr><th>" . htmlspecialchars($key) . ":</th><td>" . htmlspecialchars($value) . "</td></tr>";
}
} else {
echo "<tr><td colspan='2'>User details not found. Please update your profile.</td></tr>";
}
} catch (PDOException $e) {
error_log("Error fetching user details: " . $e->getMessage());
echo "<tr><td colspan='2'>Error fetching user details. Please try again later.</td></tr>";
}
?>
</table>
<a href="donate.html" style="text-align: center;">Donate Blood</a>
<a href="search.html" style="text-align: center;">Search for Blood</a>
<a href="myreport.php" style="text-align: center;">Medical Record</a>
<a href="locationtest.html" style="text-align: center;">Find nearest center</a>
<a href="logout.php" style="text-align: center;">Logout</a>
</body>
</html>