35667-vm/delete_grievance.php
Flatlogic Bot fd880153e8 Version 3
2025-11-15 12:00:54 +00:00

31 lines
931 B
PHP

<?php
require_once 'db/config.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['grievance_id'])) {
$grievance_id = $_POST['grievance_id'];
try {
$pdo = db();
// Also delete associated updates
$stmt = $pdo->prepare("DELETE FROM grievance_updates WHERE grievance_id = ?");
$stmt->execute([$grievance_id]);
$stmt = $pdo->prepare("DELETE FROM grievances WHERE id = ?");
$stmt->execute([$grievance_id]);
header("Location: index.php");
exit();
} catch (PDOException $e) {
// Handle database errors
error_log("Database error: " . $e->getMessage());
// You might want to show an error message to the user
header("Location: index.php?error=deletion_failed");
exit();
}
} else {
// Redirect if accessed directly or without a grievance_id
header("Location: index.php");
exit();
}
?>