-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelete_team.php
36 lines (30 loc) · 992 Bytes
/
delete_team.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
<?php
require_once 'database.php';
if (isset($_GET['id'])) {
$team_id = $_GET['id'];
try {
// START A TRANSACTION
$conn->beginTransaction();
// CHECK HOW MANY MEMBERS THE TEAM HAS
$sql = "SELECT teams.* FROM teams WHERE teams.id = ?";
$stmt = $conn->prepare($sql);
$stmt->execute([$team_id]);
$members = $stmt->fetchAll(PDO::FETCH_ASSOC);
if (!empty($members)) {
// DELETE ALL MEMBERS ASSOCIATED WITH THIS TEAM
$stmt = $conn->prepare("DELETE FROM members WHERE teams_id = ?");
$stmt->execute([$team_id]);
}
// DELETE THE TEAM
$stmt = $conn->prepare("DELETE FROM teams WHERE id = ?");
$stmt->execute([$team_id]);
// COMMIT THE TRANSACTION
$conn->commit();
header("Location: /crud_add_pdf_project/teams.php");
} catch (Exception $e) {
// ROLLBACK THE TRANSACTION IF SOMETHING HAS FAILED
$conn->rollBack();
echo "Error: " . $e->getMessage();
}
}
?>