<?php
include "dbconnect.php";

// Ensure that the 'id' parameter is passed and valid
$id = isset($_GET['id']) ? (int)$_GET['id'] : 0;

if ($id <= 0) {
    die('Invalid ID. Make sure the ID is passed correctly in the URL, like ?id=1');
}

// Debugging: print the ID to ensure it's correct
echo "ID passed: $id<br>";

// Fetch the work permit approval record from the database
$sql = "SELECT * FROM work_permit_approval WHERE id = $id";
echo "SQL Query: $sql<br>";  // Debugging the query

$result = $con->query($sql);

// Check for SQL errors
if (!$result) {
    die('Query failed: ' . $con->error);
}

// If no record is found
if ($result->num_rows == 0) {
    die('Record not found for ID: ' . $id);
}

$row = $result->fetch_assoc();

// Populate form fields with current values
$work_permit_received = $row['work_permit_received'];
$file_upload = $row['file_upload'];
$approval_date = $row['approval_date']; // Format for date input
?>
