Repository navigation
Expand file tree
/
Copy pathdelete_appointment.php
More file actions
59 lines (51 loc) · 1.72 KB
/
Copy pathdelete_appointment.php
File metadata and controls
59 lines (51 loc) · 1.72 KB
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
<?php
include 'db_connect.php';
// Start session if not already started
if (session_status() === PHP_SESSION_NONE) {
session_start();
}
// Check if admin is logged in
if (isset($_SESSION['admin_id'])) {
// Admin is logged in
if (isset($_POST['appointment_id'])) {
$appointment_id = $_POST['appointment_id'];
// Admin can delete any appointment without checking patient_id
$stmt = $conn->prepare("DELETE FROM appointments WHERE appointment_id = ?");
$stmt->bind_param("i", $appointment_id);
if ($stmt->execute()) {
// Redirect back to admin dashboard
header("Location: admin_dashboard.php");
exit();
} else {
die("Error deleting appointment: " . $stmt->error);
}
} else {
header("Location: admin_dashboard.php");
exit();
}
}
// Otherwise, if patient is logged in
elseif (isset($_SESSION['patient_id'])) {
if (isset($_POST['appointment_id'])) {
$appointment_id = $_POST['appointment_id'];
// Delete appointment only if it belongs to the logged-in patient
$stmt = $conn->prepare("DELETE FROM appointments WHERE appointment_id = ? AND patient_id = ?");
$stmt->bind_param("ii", $appointment_id, $_SESSION['patient_id']);
if ($stmt->execute()) {
// Redirect back to patient dashboard
header("Location: patient_dashboard.php");
exit();
} else {
die("Error deleting appointment: " . $stmt->error);
}
} else {
header("Location: patient_dashboard.php");
exit();
}
}
// If neither admin nor patient is logged in, redirect to homepage
else {
header("Location: index.php");
exit();
}
?>