-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin.php
157 lines (119 loc) · 4.39 KB
/
admin.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
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/2.2.16/tailwind.min.css" />
<link rel="stylesheet" href="css.css" />
<title>Admin Portal</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f5f5f5;
}
caption {
text-align: center;
margin-top: 50px;
color: #990000;
font-size: 3rem;
}
table {
margin: 50px auto;
border-collapse: collapse;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
background-color: #fff;
}
table th,
table td {
padding: 10px;
border: 1px solid #ccc;
text-align: left;
}
table th {
background-color: #990000;
color: #fff;
font-weight: bold;
}
table tr:nth-child(even) {
background-color: #f2f2f2;
}
table tr:hover {
background-color: #ddd;
}
</style>
</head>
<body>
<script>
function updateDatabase(x,y) {
console.log("called");
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
console.log("Database updated successfully!");
}
};
xhttp.open("POST", "update.php", true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
if(x.checked){
xhttp.send("email=" + y+ "&available=" + 1);
}
else{
xhttp.send("email=" + y+ "&available=" + 0);
}
}
</script>
<!-- Navigation Bar -->
<nav class="bg-red-700 p-2 mt-0 w-full">
<div class="container mx-auto flex flex-wrap items-center">
<div class="flex w-full md:w-1/2 justify-center md:justify-start text-white font-extrabold">
<a class="text-white no-underline hover:text-white hover:no-underline" href="#">
<span class="text-2xl pl-2">Blood Bank Management System</span>
</a>
</div>
<div class="flex w-full md:w-1/2 justify-center md:justify-end">
<ul class="list-reset flex justify-between flex-1 md:flex-none items-center">
<li class="flex-1 md:flex-none md:mr-3">
<a class="inline-block py-2 px-4 text-white font-bold no-underline" href="in.html">LOG-OUT</a>
</li>
</ul>
</div>
</div>
</nav>
<?php
// Establish a database connection
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "db";
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$conn = mysqli_connect("localhost", "root", "", "db");
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "SELECT * FROM tb";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "<table>";
echo "<caption>Donors Data</caption>";
echo "<tr><th>name</th><th>email</th><th>gender</th><th>age</th><th>address</th><th>pincode</th><th>mobileno</th><th>bloodgroup</th><th>username</th><th>Available</th></tr>";
while ($row = $result->fetch_assoc()) {
$x=$row["email"];
echo '<tr><td>' . $row["name"] . '</td><td>' . $row["email"] . '</td><td>' . $row["gender"] . '</td><td>' . $row['age'] .'</td><td>' . $row["address"] . '</td><td>' . $row["pincode"] .'</td><td>' . $row['mobileno'] .'</td><td>' . $row['bloodgroup'] . '</td><td>' . $row["username"] .'</td>';
echo "<td><input type='checkbox' name='checkbox' value='1' onclick='updateDatabase(this,\"$x\")'";
if ($row["available"]) {
echo 'checked';
}
echo '></td>';
}
echo "</table>";
} else {
echo "<p>No results found.</p>";
}
echo "<br><br><br>";
// Close the database connection
$conn->close();
?>
</body>
</html>