<?php

require_once("functions.php");
require_once("db-const.php");
session_start();

$mysqli = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
# check connection
if ($mysqli->connect_errno) {
    echo "<p>MySQL error no {$mysqli->connect_errno} : {$mysqli->connect_error}</p>";
    exit();
}

$imageToDelete = $_GET['image'];
$type = $_GET['type'];
$id = $_GET['id'];
$page = $_GET['page'];

$folder = "../UploadedImages/";


$sql = "DELETE FROM `image_table` WHERE  `name` LIKE '$imageToDelete'";


if (file_exists("$folder"."$imageToDelete")) {
    echo unlink("$folder"."$imageToDelete");
}

if ($mysqli->query($sql)) {
    redirect_to("../images.php?type=$type&id=$id&page=$page&msg=supp");
} else {
    echo "<p>MySQL error no {$mysqli->errno} : {$mysqli->error}</p>";
    exit();
}

?>



