<?php
include("connection.php");

if (isset($_GET['id'])) {
    $id = intval($_GET['id']); // Ensure ID is an integer

    // Get file name before deleting
    $getFile = mysqli_query($con, "SELECT resume FROM job_applications WHERE id = $id");
    if ($getFile && mysqli_num_rows($getFile) > 0) {
        $fileData = mysqli_fetch_assoc($getFile);
        $filePath = "./assets/images/team/" . $fileData['resume']; // Correct path

        // Delete file if exists
        if (!empty($fileData['resume']) && file_exists($filePath)) {
            unlink($filePath);
        }
    }

    // Delete from DB
    $del = mysqli_query($con, "DELETE FROM job_applications WHERE id = $id");

    if ($del) {
        header("Location: viewcareer.php?status=success");
        exit;
    } else {
        header("Location: viewcareer.php?status=error");
        exit;
    }
} else {
    header("Location: viewcareer.php");
    exit;
}
?>
