-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelete.php
90 lines (88 loc) · 3.11 KB
/
delete.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
<?php
session_start();
require_once 'components/db_connect.php';
// if session is not set this will redirect to login page
if( !isset($_SESSION['adm']) && !isset($_SESSION['user']) ) {
header("Location: index.php");
exit;
}
if(isset($_SESSION["user"])){
header("Location: home.php");
exit;
}
//initial bootstrap class for the confirmation message
$class = 'd-none';
//the GET method will show the info from the user to be deleted
if ($_GET['id']) {
$id = $_GET['id'];
$sql = "SELECT * FROM user WHERE id = {$id}" ;
$result = $connect->query($sql);
$data = $result->fetch_assoc();
if ($result->num_rows == 1) {
$f_name = $data['first_name'];
$l_name = $data['last_name'];
$email = $data['email'];
$date_of_birth = $data['date_of_birth'];
$picture = $data['picture'];
}
}
//the POST method will actually delete the user permanently
if ($_POST) {
$id = $_POST['id'];
$picture = $_POST['picture'];
($picture =="user.png")?: unlink("pictures/$picture");
$sql = "DELETE FROM user WHERE id = {$id}";
if ($connect->query($sql) === TRUE) {
$class = "alert alert-success";
$message = "Successfully Deleted!";
header("refresh:3;url=dashboard.php");
} else {
$class = "alert alert-danger";
$message = "The entry was not deleted due to: <br>" . $connect->error;
}
}
$connect->close();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Delete User</title>
<?php require_once 'components/boot.php'?>
<style type= "text/css">
fieldset {
margin: auto;
margin-top: 100px;
width: 70% ;
}
.img-thumbnail{
width: 70px !important;
height: 70px !important;
}
</style>
</head>
<body>
<div class="<?php echo $class; ?>" role="alert">
<p><?php echo ($message) ?? ''; ?></p>
</div>
<fieldset>
<legend class='h2 mb-3'>Delete request <img class='img-thumbnail rounded-circle' src='pictures/<?php echo $picture ?>' alt="<?php echo $f_name ?>"></legend>
<h5>You have selected the data below:</h5>
<table class="table w-75 mt-3">
<tr>
<td><?php echo "$f_name $l_name"?></td>
<td><?php echo $email?></td>
<td><?php echo $date_of_birth?></td>
</tr>
</table>
<h3 class="mb-4">Do you really want to delete this user?</h3>
<form method="post">
<input type="hidden" name="id" value="<?php echo $id ?>" />
<input type="hidden" name="picture" value="<?php echo $picture ?>" />
<button class="btn btn-danger" type="submit">Yes, delete it!</button >
<a href="dashboard.php"><button class="btn btn-warning" type="button">No, go back!</button></a>
</form>
</fieldset>
</body>
</html>