<?php
// Include your database connection file (e.g., connection.php)
include('connection.php');

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    // Retrieve the data from the form
    $id = $_POST['id'];
    $name = $_POST['name'];
    $total_salary = $_POST['total_salary'];
    $to_be_paid = $_POST['to_be_paid'];
    $salary_date = $_POST['salary_date'];
    $joining_date = $_POST['joining_date'];
    $status = $_POST['status'];
    $leaves = $_POST['leaves'];
    $employee_id = $_POST['employee_id'];
    $per_day_salary = $_POST['per_day_salary'];
    $working_days = $_POST['working_days'];
    $contact_number = $_POST['contact_number'];
    $email = $_POST['email'];

    // Define your SQL query to update the database record
    $query = "UPDATE hr_payroll
              SET
              name = '$name',
              total_salary = '$total_salary',
              to_be_paid = '$to_be_paid',
              salary_date = '$salary_date',
              joining_date = '$joining_date',
              status = '$status',
              leaves = '$leaves',
              employee_id = '$employee_id',
              per_day_salary = '$per_day_salary',
              working_days = '$working_days',
              contact_number = '$contact_number',
              email = '$email'
              WHERE id = $id";

    // Execute the query
    $result = mysqli_query($conn, $query);

    // Check if the query was successful
    if ($result) {
        // Redirect to a success page or do something else
        // header('Location: payroll.php');
        header("Location: payroll.php?success=Payroll Updated Successfully!!!");

        exit;
    } else {
        // Handle the error, e.g., display an error message
        echo 'Error updating record: ' . mysqli_error($conn);
    }
}
?>
