-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelete_record.php
45 lines (35 loc) · 1.24 KB
/
delete_record.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
<?php
// This code will handle process of delete class in record.html (RECORD SUB-MODULE)
$servername = "localhost";
header('Content-Type: application/json');
$input = json_decode(file_get_contents('php://input'), true);
$class_id = $input['class_id'];
if (!$class_id) {
echo json_encode(['success' => false, 'message' => 'Invalid class ID']);
exit;
}
include 'database.php';
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die(json_encode(['success' => false, 'message' => 'Connection failed: ' . $conn->connect_error]));
}
$conn->begin_transaction();
try {
// Delete from attendance table
$stmt = $conn->prepare("DELETE FROM attendance WHERE class_id = ?");
$stmt->bind_param("i", $class_id);
$stmt->execute();
$stmt->close();
// Delete from class table
$stmt = $conn->prepare("DELETE FROM class WHERE class_id = ?");
$stmt->bind_param("i", $class_id);
$stmt->execute();
$stmt->close();
$conn->commit();
echo json_encode(['success' => true]);
} catch (Exception $e) {
$conn->rollback();
echo json_encode(['success' => false, 'message' => 'Transaction failed: ' . $e->getMessage()]);
}
$conn->close();
?>