55ok

Mini

Direktori : /home/u307599615/domains/costumeonrent.in/public_html/admin/
Upload File :
Current File : /home/u307599615/domains/costumeonrent.in/public_html/admin/deletecostumes.php

<?php
include("connection.php");

// Get product ID safely
$c_id = isset($_GET['c_id']) ? intval($_GET['c_id']) : 0;

if ($c_id > 0) {
    // Fetch the product
    $sql = "SELECT * FROM `costumes` WHERE `c_id` = '$c_id'";
    $query = mysqli_query($con, $sql);

    if ($query && mysqli_num_rows($query) > 0) {
        $row = mysqli_fetch_assoc($query);
        $old_images = json_decode($row['Image'], true);

        // Delete product record
        $deleteSql = "DELETE FROM `costumes` WHERE `c_id` = '$c_id'";
        $deleteQuery = mysqli_query($con, $deleteSql);

        if ($deleteQuery) {
            // Delete images from folder
            if (!empty($old_images) && is_array($old_images)) {
                foreach ($old_images as $img) {
                    $filePath = "./assets/images/categorie/" . $img;
                    if (file_exists($filePath)) {
                        unlink($filePath);
                    }
                }
            } elseif (!empty($row['Image'])) {
                // Handle single image (non-JSON)
                $filePath = "./assets/images/categorie/" . $row['Image'];
                if (file_exists($filePath)) {
                    unlink($filePath);
                }
            }

            // Redirect after delete
            header("Location: viewcostumes.php");
            exit();
        } else {
            echo "Error deleting record: " . mysqli_error($con);
        }
    } else {
        echo "Product not found.";
    }
} else {
    echo "Invalid product ID.";
}
?>

Zerion Mini 1.0