-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelete_phone.php
34 lines (27 loc) · 1.07 KB
/
delete_phone.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
<?php
include('dbcon.php');
if (isset($_GET['id'])) {
$id = $_GET['id'];
// Delete associated user phones first
$deleteUserPhonesQuery = "DELETE FROM userphones WHERE userID = '$id'";
$deleteUserPhonesResult = mysqli_query($connection, $deleteUserPhonesQuery);
if (!$deleteUserPhonesResult) {
die("User phones deletion failed: " . mysqli_error($connection));
}
// Delete associated sensor readings
$deleteReadingsQuery = "DELETE FROM sensorreadings WHERE userID = '$id'";
$deleteReadingsResult = mysqli_query($connection, $deleteReadingsQuery);
if (!$deleteReadingsResult) {
die("Sensor readings deletion failed: " . mysqli_error($connection));
}
// Delete the phone
$deletePhoneQuery = "DELETE FROM phones WHERE phoneID = '$id'";
$deletePhoneResult = mysqli_query($connection, $deletePhoneQuery);
if (!$deletePhoneResult) {
die("Phone deletion failed: " . mysqli_error($connection));
} else {
header('location:index.php?delete_msg=You have deleted the record.');
exit();
}
}
?>