prepare("SELECT image FROM products WHERE id = ?"); $stmt_img->execute([$prod_id]); $img_name = $stmt_img->fetchColumn(); $stmt = $pdo->prepare("DELETE FROM products WHERE id = ?"); $stmt->execute([$prod_id]); // Delete custom image if (!empty($img_name) && file_exists(__DIR__ . '/../assets/images/' . $img_name) && strpos($img_name, 'prod_') !== false) { @unlink(__DIR__ . '/../assets/images/' . $img_name); } $msg = 'Product removed from collection successfully.'; } catch (Exception $e) { $msg = 'Failed to delete product: ' . $e->getMessage(); $msg_type = 'danger'; } } // Fetch search queries if any $search = isset($_GET['search']) ? trim($_GET['search']) : ''; $where_clause = ''; $params = []; if (!empty($search)) { $where_clause = " WHERE p.name LIKE ? OR p.description LIKE ? OR c.name LIKE ? "; $params = ["%$search%", "%$search%", "%$search%"]; } // Fetch all products try { $stmt = $pdo->prepare("SELECT p.*, c.name as category_name FROM products p LEFT JOIN categories c ON p.category_id = c.id " . $where_clause . " ORDER BY p.id DESC"); $stmt->execute($params); $products = $stmt->fetchAll(); } catch (Exception $e) { $products = []; } ?>
Update inventories, pricing catalogs, and spotlight featured products.