prepare("SELECT thumbnail FROM products WHERE id = ?"); $product->execute([$id]); $p = $product->fetch(); if ($p && $p['thumbnail']) { @unlink(UPLOADS_PATH . 'products/' . $p['thumbnail']); } $db->prepare("DELETE FROM product_images WHERE product_id = ?")->execute([$id]); $db->prepare("DELETE FROM products WHERE id = ?")->execute([$id]); admin_set_flash('success', 'Product deleted successfully'); header('Location: ' . ADMIN_PATH . 'pages/products.php'); exit; } $page_num = max(1, intval($_GET['page'] ?? 1)); $per_page = 20; $offset = ($page_num - 1) * $per_page; $search = $_GET['search'] ?? ''; $category_filter = $_GET['category'] ?? ''; $where = "1=1"; $params = []; if ($search) { $where .= " AND (p.name LIKE ? OR p.sku LIKE ?)"; $params[] = "%$search%"; $params[] = "%$search%"; } if ($category_filter) { $where .= " AND p.category_id = ?"; $params[] = $category_filter; } $count_stmt = $db->prepare("SELECT COUNT(*) FROM products p WHERE $where"); $count_stmt->execute($params); $total = $count_stmt->fetchColumn(); $total_pages = ceil($total / $per_page); $stmt = $db->prepare("SELECT p.*, c.name as category_name, b.name as brand_name FROM products p LEFT JOIN categories c ON p.category_id = c.id LEFT JOIN brands b ON p.brand_id = b.id WHERE $where ORDER BY p.created_at DESC LIMIT $per_page OFFSET $offset"); $stmt->execute($params); $products = $stmt->fetchAll(); $categories = get_categories(); ?>

All Products ()

Add New Product
Image Name Category Price Stock Status Actions
SKU:
0): ?>
1): ?>
1): ?>