-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete-user.php
More file actions
40 lines (33 loc) · 976 Bytes
/
delete-user.php
File metadata and controls
40 lines (33 loc) · 976 Bytes
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
<?php
//Contact US
require 'crud/databaseconfig.php';
if(isset($_POST["delete"])){
$id = $_POST['id'];
$sql = "DELETE FROM users WHERE id =:id";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':id', $id);
$delete = $stmt->execute();
header('Location:admin.php');
exit;
}
?>
<h1>Delete a User by ID</h1>
<form id="form" action="delete-user.php" method="post">
<input type="text" id="id" name="id" placeholder="put the user id"><br>
<button type="submit" name="delete">Delete</button>
</form>
<?php
$query = $conn->query('SELECT id , username FROM users');
$users = $query->fetchAll();
?>
<table class="demo" border="1">
<tr>
<th>ID</th>
<th>Username</th>
</tr>
<?php foreach($users as $user):?>
<tr>
<td><?php echo $user['id'];?></td>
<td><?php echo $user['username'];?></td>
</tr>
<?php endforeach;?>