<?php

require '../config.php';
session_start();

$userId =
intval($_SESSION['user_id']);

if($_SERVER['REQUEST_METHOD']=='POST'){

    $amount =
    floatval($_POST['amount']);

    $reason =
    trim($_POST['reason']);

    $stmt = $conn->prepare("

    INSERT INTO salary_advances
    (
        employee_id,
        amount,
        reason,
        request_date
    )

    VALUES
    (
        ?,?,?,CURDATE()
    )

    ");

    $stmt->bind_param(
        "ids",
        $userId,
        $amount,
        $reason
    );

    $stmt->execute();

    header(
        "Location: salary_advance_request.php?saved=1"
    );

    exit;
}