<?php
// Database connection parameters
include('connection.php');

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    // Retrieve data from the form
    $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'];
    $datetime = date("d/m/y h:i:sa");

    // SQL query to insert data into a MySQL table
    $sql = "INSERT INTO hr_payroll (name, total_salary, to_be_paid, salary_date, joining_date, status, leaves, employee_id, per_day_salary, working_days, contact_number, email,datetime)
            VALUES ('$name', '$total_salary', '$to_be_paid', '$salary_date', '$joining_date', '$status', '$leaves', '$employee_id', '$per_day_salary', '$working_days', '$contact_number', '$email','$datetime')";

    if ($conn->query($sql) === TRUE) {
        // Redirect to a thank you page or display a confirmation message
        // header('Location: payroll.php');
        header("Location: payroll.php?success=Payroll Added Successfully!!!");

        exit();
    } else {
        echo "Error: " . $sql . "<br>" . $conn->error;
    }
    
    // Close the database connection
    $conn->close();
}
?>
