<?php
include('db_connection.php');

if (isset($_GET['payroll_id'])) {
    $payroll_id = $_GET['payroll_id'];

    // Prepare and execute the delete query
    $query = "DELETE FROM payrolls WHERE payroll_id = ?";
    $stmt = $conn->prepare($query);
    $stmt->bind_param("i", $payroll_id);

    if ($stmt->execute()) {
        // If successful, redirect to view_payroll.php
        header("Location: view_payroll.php?message=Payroll+record+deleted+successfully");
    } else {
        // If an error occurs, redirect to view_payroll.php with an error message
        header("Location: view_payroll.php?error=Failed+to+delete+payroll+record");
    }

    $stmt->close();
} else {
    // If no payroll_id is provided, redirect to view_payroll.php
    header("Location: view_payroll.php?error=No+payroll+ID+provided");
}

$con->close();
?>
