<?php
// Connect to the database
require_once('db.php');

// Retrieve the submission ID and filenames from the form data
$id = $_POST['id'];
$document1 = $_POST['document1'];
$document2 = $_POST['document2'];

// Delete the submission record from the database
$sql = "DELETE FROM submissions WHERE id=$id";
if ($conn->query($sql) === TRUE) {
    echo "Submission record deleted successfully.";
} else {
    echo "Error deleting submission record: " . $conn->error;
}

// Delete the uploaded files from the server
$target_dir = "uploads/";
if($document1) {
    $target_file1 = $target_dir . $document1;
    if(file_exists($target_file1)) {
        unlink($target_file1);
        echo "The file " . $document1 . " has been deleted.";
    }
}
if($document2) {
    $target_file2 = $target_dir . $document2;
    if(file_exists($target_file2)) {
        unlink($target_file2);
        echo "The file " . $document2 . " has been deleted.";
    }
}

$conn->close();
?>
