-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelete_page.php
49 lines (38 loc) · 1.65 KB
/
delete_page.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
<?php
include('dbcon.php');
if (isset($_GET['id'])) {
$id = $_GET['id'];
// Delete associated sensor readings
$deleteReadingsQuery = "DELETE FROM sensorreadings WHERE roomID IN (SELECT roomID FROM room WHERE userID = '$id')";
$deleteReadingsResult = mysqli_query($connection, $deleteReadingsQuery);
if (!$deleteReadingsResult) {
die("Sensor readings deletion failed: " . mysqli_error($connection));
}
// Delete associated bookings
$deleteBookingsQuery = "DELETE FROM booking WHERE userID = '$id'";
$deleteBookingsResult = mysqli_query($connection, $deleteBookingsQuery);
if (!$deleteBookingsResult) {
die("Bookings deletion failed: " . mysqli_error($connection));
}
// Delete associated user phones
$deleteUserPhonesQuery = "DELETE FROM userphones WHERE userID = '$id'";
$deleteUserPhonesResult = mysqli_query($connection, $deleteUserPhonesQuery);
if (!$deleteUserPhonesResult) {
die("User phones deletion failed: " . mysqli_error($connection));
}
// Delete associated rooms
$deleteRoomsQuery = "DELETE FROM room WHERE userID = '$id'";
$deleteRoomsResult = mysqli_query($connection, $deleteRoomsQuery);
if (!$deleteRoomsResult) {
die("Rooms deletion failed: " . mysqli_error($connection));
}
// Delete the student
$deleteStudentQuery = "DELETE FROM student WHERE userID = '$id'";
$deleteStudentResult = mysqli_query($connection, $deleteStudentQuery);
if (!$deleteStudentResult) {
die("Student deletion failed: " . mysqli_error($connection));
} else {
header('location:index.php?delete_msg=You have deleted the record.');
}
}
?>