<?php
// Include the database configuration file
include 'config.php';

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// Retrieve form data
$itemName = $_POST['drinkName'];
$itemPrice = $_POST['drinkPrice'];
$itemImage = basename($_FILES["drinkImage"]["name"]);

// Directory where you want to store the uploaded images (public_html directory)
$targetDir = "public_html/";
$targetFilePath = $targetDir . $itemImage;

// Move uploaded file to specified directory
if (move_uploaded_file($_FILES["drinkImage"]["tmp_name"], $targetFilePath)) {
    // Insert data into database
    $sql = "INSERT INTO drink_items (name, price, image) VALUES ('$itemName', '$itemPrice', '$itemImage')";
    if ($conn->query($sql) === TRUE) {
        echo "Drink item uploaded and inserted into database successfully!";
    } else {
        echo "Error: " . $sql . "<br>" . $conn->error;
    }
} else {
    echo "Sorry, there was an error uploading your file.";
}

$conn->close();
?>
