📁 File Manager
Editing:
/home/wedigitalindia/public_html/admin/delete_product.php
<?php include("connection.php"); if (isset($_GET['p_id']) && is_numeric($_GET['p_id'])) { $p_id = intval($_GET['p_id']); // 1. Get old image name $sql = "SELECT * FROM `product` WHERE `p_id` = $p_id"; $result = mysqli_query($con, $sql); if ($result && mysqli_num_rows($result) > 0) { $row = mysqli_fetch_assoc($result); $oldImage = $row['Image']; // 2. Delete record from database $deleteSql = "DELETE FROM `product` WHERE `p_id` = $p_id"; $deleteResult = mysqli_query($con, $deleteSql); if ($deleteResult) { // 3. Delete image from folder if it exists $imagePath = "./assets/images/service/" . $oldImage; if (!empty($oldImage) && file_exists($imagePath)) { unlink($imagePath); } // 4. Redirect after successful deletion header("Location: view_product.php"); exit(); } else { echo "Failed to delete record."; } } else { echo "Record not found."; } } else { echo "Invalid ID."; } ?>
Save
Cancel