-
Notifications
You must be signed in to change notification settings - Fork 0
/
userAdmin.php
114 lines (97 loc) · 2.86 KB
/
userAdmin.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
<?php
session_start();
include ("database/connection.php");
include ("_admin.php");
$conn = new mysqli('localhost', 'root', '', 'travel');
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT `user_name`, `email`, `number`, `Fplace`, `address` FROM `users`;";
$result = $conn->query($sql);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Users Table</title>
<style>
h2{
text-align: center;
margin: 20px;
}
table {
width: 100%;
border-collapse: collapse;
}
th, td {
border: 1px solid #ddd;
padding: 8px;
}
th {
background-color: #f2f2f2;
text-align: left;
}
button {
padding: 5px 10px;
color: white;
background-color: red;
border: none;
cursor: pointer;
}
button:hover {
background-color: darkred;
}
</style>
<script>
function deleteUser(button, userName) {
var row = button.parentNode.parentNode;
var userName = row.cells[0].innerText;
var xhr = new XMLHttpRequest();
xhr.open("POST", "delete_user.php", true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && xhr.status === 200) {
if (xhr.responseText === "success") {
var table = document.getElementById("userTable");
table.deleteRow(row.rowIndex);
} else {
alert("Failed to delete the row.");
}
}
};
xhr.send("user_name=" + encodeURIComponent(userName));
}
</script>
</head>
<body>
<h2>Users Table</h2>
<table id="userTable">
<tr>
<th>User Name</th>
<th>Email</th>
<th>Number</th>
<th>Fplace</th>
<th>Address</th>
<th>Action</th>
</tr>
<?php
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
echo "<tr>";
echo "<td>" . $row["user_name"] . "</td>";
echo "<td>" . $row["email"] . "</td>";
echo "<td>" . $row["number"] . "</td>";
echo "<td>" . $row["Fplace"] . "</td>";
echo "<td>" . $row["address"] . "</td>";
echo "<td><button onclick='deleteUser(this, \"" . $row["user_name"] . "\")'>Block</button></td>";
echo "</tr>";
}
} else {
echo "<tr><td colspan='6'>No records found</td></tr>";
}
$conn->close();
?>
</table>
</body>
</html>