begin_transaction();
try {
// Delete from Course_Group_Schedule where Group_ID matches
$deleteScheduleQuery = "DELETE FROM Course_Group_Schedule_Main WHERE Group_ID = ?";
$stmt = $mysqli->prepare($deleteScheduleQuery);
$stmt->bind_param('i', $Group_ID);
$stmt->execute();
$stmt->close();
// Delete from Schedule_Course_for_Group where Group_ID matches
$deleteScheduleQuery = "DELETE FROM Schedule_Course_for_Group WHERE Group_ID = ?";
$stmt = $mysqli->prepare($deleteScheduleQuery);
$stmt->bind_param('i', $Group_ID);
$stmt->execute();
$stmt->close();
// Delete from Manager_Group_Name (groups table) where Group_ID matches
$deleteGroupQuery = "DELETE FROM Manager_Group_Name WHERE Group_ID = ?";
$stmt = $mysqli->prepare($deleteGroupQuery);
$stmt->bind_param('i', $Group_ID);
$stmt->execute();
$stmt->close();
//// Delete from Teacher_Course_Assignments (groups table) where Group_ID matches
$deleteGroupQuery = "DELETE FROM Teacher_Course_Assignments WHERE Group_ID = ?";
$stmt = $mysqli->prepare($deleteGroupQuery);
$stmt->bind_param('i', $Group_ID);
$stmt->execute();
$stmt->close();
// Commit the transaction
$mysqli->commit();
echo "Group deleted successfully"; // Return success message
} catch (Exception $e) {
// Rollback the transaction if anything goes wrong
$mysqli->rollback();
echo "error"; // Return error message
}
}
?>