<?php
require_once('dbh.php');

error_reporting(E_ALL);
ini_set('display_errors', 1);

if (!isset($_GET['id']) || empty($_GET['id'])) {
    die("Error: Missing or invalid 'id' parameter.");
}

if (!isset($_POST['reason']) || !isset($_POST['travel_date']) || !isset($_POST['start_location']) || !isset($_POST['route'])) {
    die("Error: Missing required form data.");
}

$id = mysqli_real_escape_string($conn, $_GET['id']);
$reason = mysqli_real_escape_string($conn, $_POST['reason']);
$travel_date = mysqli_real_escape_string($conn, $_POST['travel_date']);
$start_location = mysqli_real_escape_string($conn, $_POST['start_location']);
$route = mysqli_real_escape_string($conn, $_POST['route']);

$sql4 = "INSERT INTO `transport` (`id`, `token`, `travel_date`, `route`, `start_location`, `reason`, `status1`) 
         VALUES ('$id', '', '$travel_date', '$route', '$start_location', '$reason', 'Pending')";

if (mysqli_query($conn, $sql4)) {
    header("Location: ../eloginwel.php?id=$id");
    exit();
} else {
    error_log("Database error: " . mysqli_error($conn));
    die("Error: Unable to save data. Please try again later.");
}

mysqli_close($conn);
?>


