<?php
session_start();
include("connect.php");
// Retrieve user ID from session
$userid = $_SESSION['user_id'] ;  

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

// Retrieve uploaded file paths from POST data
$doctorname=($_POST['doctorname'] ?? '')
$form_upload  = basename($_POST['uploaded_form_file'] ?? '');
$photo_upload = basename($_POST['uploaded_photo_file'] ?? '');
$video_upload = basename($_POST['uploaded_video_file'] ?? '');
$approval_status="";
$approval_by="";
// Basic validation to ensure user ID and at least one file path is provided
if ($userid && ($form_upload || $photo_upload || $video_upload)) {
    // Prepare SQL statement
    $sql = "INSERT INTO camp_upload (userid, doctorname,form_upload, photo_upload, video_upload,approval_status,approval_by) VALUES (?, ?, ?, ?,?,?)";

    // Prepare and execute the statement
    if ($stmt = $conn->prepare($sql)) {
        $stmt->bind_param("sssssss", $userid,$doctorname, $form_upload, $photo_upload, $video_upload,$approval_status,$approval_by);
        $stmt->execute();

        // Check if the insertion was successful
        if ($stmt->affected_rows > 0) {
            echo "<script>alert('Upload information saved successfully.'); window.location.href='thank-you.php';</script>";
        } else {
            echo "<script>alert('Failed to save upload information. Please try again.'); window.location.href='abm-dashboard.php';</script>";
        }

        $stmt->close();
    } else {
        echo "<script>alert('Database error.'); history.back();</script>";
    }
} else {
    echo "<script>alert('Invalid data. Please upload files first.'); history.back();</script>";
}
}

$conn->close();
?>