prepare("DELETE FROM shopping_items WHERE id = ?"); $stmt->execute([$itemIdToDelete]); } catch (PDOException $e) { error_log("Database error: " . $e->getMessage()); } } // Handle item purchase status update if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['item_id_to_toggle'])) { $itemIdToToggle = $_POST['item_id_to_toggle']; try { $pdo = db(); $stmt = $pdo->prepare("UPDATE shopping_items SET is_purchased = !is_purchased WHERE id = ?"); $stmt->execute([$itemIdToToggle]); } catch (PDOException $e) { error_log("Database error: " . $e->getMessage()); } } // Handle new item creation if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['item_name'])) { $itemName = trim($_POST['item_name']); $quantity = trim($_POST['quantity']); if (!empty($itemName)) { try { $pdo = db(); $stmt = $pdo->prepare("INSERT INTO shopping_items (item_name, quantity) VALUES (?, ?)"); $stmt->execute([$itemName, $quantity]); } catch (PDOException $e) { error_log("Database error: " . $e->getMessage()); } } } // Fetch all shopping items $items = []; try { $pdo = db(); $stmt = $pdo->query("SELECT id, item_name, quantity, is_purchased FROM shopping_items ORDER BY is_purchased ASC, created_at DESC"); $items = $stmt->fetchAll(); } catch (PDOException $e) { error_log("Database error: " . $e->getMessage()); } ?> Shopping List

Shopping List

Manage your shopping lists.

Add New Item

Your Shopping List

No items in your shopping list yet.

onchange="this.form.submit()" class="h-5 w-5 rounded border-gray-300 text-yellow-500 focus:ring-yellow-500">
()
Back to Home