35604-vm/api/save_shopping_list.php
Flatlogic Bot d7b90335da 26.01.26
2026-01-26 21:02:05 +00:00

22 lines
645 B
PHP

<?php
header('Content-Type: application/json');
require_once __DIR__ . '/auth_helper.php';
if (!is_logged_in()) {
echo json_encode(['success' => false, 'error' => 'Not authenticated']);
exit;
}
try {
$data = json_decode(file_get_contents('php://input'), true);
$shoppingList = $data['shopping_list'] ?? null;
$pdo = db();
$stmt = $pdo->prepare("UPDATE users SET shopping_list = ? WHERE id = ?");
$stmt->execute([json_encode($shoppingList), get_logged_in_user_id()]);
echo json_encode(['success' => true]);
} catch (PDOException $e) {
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
}