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; ?>
| Product Name | Category | Quantity | Expiration | Status | Actions |
|---|---|---|---|---|---|
| No items in your pantry yet. Add some! | |||||
| = htmlspecialchars($p['name']) ?> | = htmlspecialchars($p['category']) ?> | = htmlspecialchars($p['quantity']) ?> | = $p['expiration_date'] ? date('M d, Y', strtotime($p['expiration_date'])) : '-' ?> | = $status_text ?> | |