-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelete_project.php
39 lines (33 loc) · 1.2 KB
/
delete_project.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
<?php
session_start();
include 'connectDB.php';
if(isset($_POST['project_id']) && is_numeric($_POST['project_id'])) {
$project_id = $_POST['project_id'];
// Start transaction
$conn->begin_transaction();
try {
// Delete child rows first
$stmt = $conn->prepare("DELETE FROM project_members WHERE project_id = ?");
$stmt->bind_param("i", $project_id);
$stmt->execute();
$stmt->close();
// Now, delete the parent row from 'projects'
$stmt = $conn->prepare("DELETE FROM projects WHERE project_id = ?");
$stmt->bind_param("i", $project_id);
if ($stmt->execute()) {
echo "Project and related tasks deleted successfully.";
$conn->commit(); // Commit the transaction
} else {
echo "Error deleting project.";
$conn->rollback(); // Rollback the transaction in case of failure
}
$stmt->close();
} catch (Exception $e) {
$conn->rollback(); // Rollback the transaction on any error
echo "An error occurred: " . $e->getMessage();
}
$conn->close();
} else {
echo "Invalid project ID.";
}
?>