<?php

include("connection.php");

// Check if the form is submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // Capture form data
    $title = $_POST["title"];
    $platform = $_POST["platfrom"];
    $url = $_POST["url"];
    $description = $_POST["discription"];
    $assign_task = $_POST["assign_task"];
    $currentDateTime = date('Y-m-d H:i:s');

    // File Uploads
    $videoFile = $_FILES["video_file"];
    $imageFile = $_FILES["image_file"];
    $audioFile = $_FILES["audio_file"];
    $pdfFile = $_FILES["pdf_file"];

    // File Paths for Uploads
    $videoPath = "uploads/" . $videoFile["name"];
    $imagePath = "uploads/" . $imageFile["name"];
    $audioPath = "uploads/" . $audioFile["name"];
    $pdfPath = "uploads/" . $pdfFile["name"];

    // Move uploaded files to a specific directory
    move_uploaded_file($videoFile["tmp_name"], $videoPath);
    move_uploaded_file($imageFile["tmp_name"], $imagePath);
    move_uploaded_file($audioFile["tmp_name"], $audioPath);
    move_uploaded_file($pdfFile["tmp_name"], $pdfPath);

    // SQL query to insert data into the database
    $sql = "INSERT INTO add_project (title, platform, url, task_discription, video, image, audio,assign_task, pdf,datetime)
            VALUES ('$title', '$platform', '$url', '$description',  '$videoPath', '$imagePath', '$audioPath','$assign_task', '$pdfPath','$currentDateTime')";

    // Execute the query
    if (mysqli_query($conn, $sql)) {

        // echo "Task created successfully!";
        header("Location: add-projects.php?success=Project Created Successfully!!!!");
        exit(); // Exit to prevent further script execution


    } else {
        echo "Error: " . mysqli_error($conn);
    }

    // Close the database connection
    mysqli_close($conn);
}
?>