-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathusers.php
97 lines (82 loc) · 2.7 KB
/
users.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
<?php
// Include Database Connection
include("config/database.php");
include("include/alert.php");
include("include/middleware.php");
// Connect Database
$conn = database_Connect();
// Retrieve all user records from the database
$sql = "SELECT * FROM users";
$result=$conn->query($sql);
// Delete User Code
if(isset($_GET['id']) && $_GET['id']!=null) {
// Sanitize the input to prevent SQL injection
$id = intval($_GET['id']);
// Delete user record from the database based on the provided ID
$sql1 = "DELETE FROM users WHERE id=$id";
$result1 = $conn->query($sql1);
if($result1 && $conn->affected_rows>0){
$_SESSION['Sucess'] = "Record Deleted Sucessfully";
header("Location: users.php");
}
else{
$_SESSION['Error'] = "Record not Found";
header("Location: users.php");
}
}
?>
<!DOCTYPE html>
<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">
<link href="css/style.css" rel="stylesheet">
<title>PHP CRUD Application</title>
</head>
<body>
<section class="section">
<h2>All Users</h2>
<table id="users">
<thead>
<tr>
<th>Username</th>
<th>Created At</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
if ($result->num_rows > 0) {
while ($row = mysqli_fetch_assoc($result)) {
?>
<tr>
<td>
<?php echo $row['username'] ?>
</td>
<td>
<?php echo date("d-m-Y h:i A", strtotime($row['created_at'])) ?>
</td>
<td>
<a href="edit-user.php?id=<?php echo $row['id'] ?>" class="button edit">Edit</a>
<a href="users.php?id=<?php echo $row['id'] ?>" class="button delete">Delete</a>
</td>
</tr>
<?php }
} else {
echo "<tr><td colspan='3'>No record found!</td></tr>";
}
?>
</tbody>
</table>
<div class="container" style="background-color:#f1f1f1">
<a href="logout.php" class="footerbtn">Logout</a>
<a href="users.php" class="footerbtn">Refresh</a>
</div>
</section>
</body>
</html>
<?php
// Close Database Connection
database_Close($conn);
?>