-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin.php
More file actions
103 lines (84 loc) · 2.88 KB
/
admin.php
File metadata and controls
103 lines (84 loc) · 2.88 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
102
103
<!DOCTYPE html>
<!-- Coding By CodingNepal - youtube.com/codingnepal -->
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Realtime Chat App</title>
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.2/css/all.min.css"/>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-KK94CHFLLe+nY2dmCWGMq91rCGa5gtU4mk92HdvYe+M/SXH301p5ILy+dN9+nJOZ" crossorigin="anonymous">
</head>
<body>
<?php
$hostname = "localhost";
$username = "root";
$password = "";
$dbname = "chatappv1";
$conn = mysqli_connect($hostname, $username, $password, $dbname);
if(!$conn){
echo "Database connection error".mysqli_connect_error();
}
$sql = "SELECT `user_id`, `unique_id`, `fname`, `lname`, `email` FROM `users`";
$result = mysqli_query($conn, $sql);
?>
<div class="wrapper">
<section class="users">
<header style="font-size: 16px;">Welcome to Admin Panel</header>
<div class="content">
<!-- <div class="admin_container">
<h1>Welcome to Admin Page</h1>
</div>-->
<!-- <div class="tab"> -->
<table style="width:100%">
<tr>
<th>ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>Action</th>
</tr>
<?php while($row = mysqli_fetch_assoc($result)) { ?>
<tr style="margin:5px">
<td><?php echo $row['user_id']; ?></td>
<td><?php echo $row['fname']; ?></td>
<td><?php echo $row['lname']; ?></td>
<td>
<form method="post" action="admin.php">
<input type="hidden" name="id" value="<?php echo $row['user_id']; ?>">
<input type="submit" name="submit" value="Remove" class="btn btn-outline-danger btn-sm">
</form>
</td>
</tr>
<?php } ?>
</table>
<!-- </div> -->
</div>
</section>
</div>
</body>
<?php
mysqli_close($conn);
?>
<?php
session_start();
if (isset($_POST['submit'])) {
$id = $_POST['id'];
// echo $id;
// Connect to database
$hostname = "localhost";
$username = "root";
$password = "";
$dbname = "chatappv1";
$conn = mysqli_connect($hostname, $username, $password, $dbname);
if(!$conn){
echo "Database connection error".mysqli_connect_error();
}
// Delete user from database
$sql = "DELETE FROM `users` WHERE user_id=$id";
mysqli_query($conn, $sql);
header("location: admin.php");
mysqli_close($conn);
// Close connection
}
?>