<?php
// Include the database configuration file
include '../config.php';
// Initialize message variable
  $msg = "";


// upload VMC to Dbase
  // If upload button is clicked ...
  if (isset($_POST['upload'])) {
    $vmc_pic = $_FILES['vmc_pic']['name'];
    $vmc_title = mysqli_real_escape_string($db, $_POST['vmc_title']);
    $vmc_category = mysqli_real_escape_string($db, $_POST['vmc_category']);

    // image file directory
    $target_file = "uploads/".basename($vmc_pic);

    $sql_vmc = "INSERT INTO vmc (vmc_pic,vmc_title,vmc_category) VALUES ('$vmc_pic', '$vmc_title','$vmc_category')";
    // execute query
    mysqli_query($db, $sql_vmc);

    if (move_uploaded_file($_FILES['vmc_pic']['tmp_name'], $target_file)) {
        $msg = "Image uploaded successfully";

      header("Location: ../home.php");
    }else{
        $msg = "Failed to upload image";
    }
  }
?>
