<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // Form data
    $productName = $_POST['title_name'];
    $productImage = $_FILES['product_image']['name'];
    $productImageTmp = $_FILES['product_image']['tmp_name'];
    $label = $_POST['Label'];

    // Current datetime
    $currentDatetime = date("Y-m-d H:i:s");

    // Database connection
    include("connection.php"); // Include your database connection file

    // Upload directory
    $uploadDirectory = 'img/'; // Define your upload directory

    // Move uploaded file to the designated directory
    $uploadedFilePath = $uploadDirectory . $productImage;
    move_uploaded_file($productImageTmp, $uploadedFilePath);

    // Insert data into the database
    $sql = "INSERT INTO add_catalouge (title, product_image, label, datetime)
            VALUES ('$productName', '$uploadedFilePath', '$label', '$currentDatetime')";

    if ($conn->query($sql) === TRUE) {

        // echo "Data inserted successfully";
         header("Location:catalouge.php?msg=1");

    } else {
        header("Location:catalouge.php?msg=2");
    }

    $conn->close();
}
?>