prepare("INSERT INTO products (name, category, quantity, expiration_date) VALUES (?, ?, ?, ?)"); $stmt->execute([$name, $category, $quantity, $expiration_date]); } } elseif ($_POST['action'] === 'delete') { $id = (int)($_POST['id'] ?? 0); if ($id) { $stmt = db()->prepare("DELETE FROM products WHERE id = ?"); $stmt->execute([$id]); } } header('Location: index.php'); exit; } // Fetch Products $products = db()->query("SELECT * FROM products ORDER BY expiration_date ASC")->fetchAll(); $today = new DateTime(); $expiring_soon_days = 7; ?> Home Pantry Tracker
diff($exp_date); $days = (int)$diff->format("%r%a"); if ($days < 0) $expired_count++; elseif ($days <= $expiring_soon_days) $warning_count++; } } ?>
Total Items
Expired
Expiring Soon
Inventory List
Sorted by expiration date
diff($exp_date); $days = (int)$diff->format("%r%a"); if ($days < 0) { $status_class = 'status-expired'; $badge_class = 'badge-expired'; $status_text = 'Expired'; } elseif ($days <= $expiring_soon_days) { $status_class = 'status-warning'; $badge_class = 'badge-warning'; $status_text = 'Expiring Soon'; } } ?>
Product Name Category Quantity Expiration Status Actions
No items in your pantry yet. Add some!