<?php
// process_edit_payroll.php

include('db_connection.php');

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $payroll_id = $_POST['payroll_id'];
    $teacher_id = $_POST['teacher_id'];
    $salary = $_POST['salary'];
    $payment_date = $_POST['payment_date'];
    $payment_method = $_POST['payment_method'];
    $notes = $_POST['notes'];

    // Update the payroll record
    $query = "UPDATE payrolls SET salary = ?, payment_date = ?, payment_method = ?, notes = ? WHERE payroll_id = ?";
    $stmt = $conn->prepare($query);
    $stmt->bind_param("dsssi", $salary, $payment_date, $payment_method, $notes, $payroll_id);

    if ($stmt->execute()) {
        // Redirect to a confirmation page or back to the payroll list
        header('Location: manage_payroll.php?message=Payroll updated successfully');
    } else {
        echo "Error updating record: " . $conn->error;
    }

    $stmt->close();
    $conn->close();
}
?>
