false, 'error' => 'Invalid request']; if ($_SERVER['REQUEST_METHOD'] === 'POST') { $projectId = $_POST['projectId'] ?? null; $month = $_POST['month'] ?? null; $amount = $_POST['amount'] ?? null; if ($projectId && $month && $amount !== null) { try { $pdo = db(); $stmt = $pdo->prepare("UPDATE expensesMonthly SET amount = :amount WHERE projectId = :projectId AND month = :month"); $stmt->execute([ ':amount' => $amount, ':projectId' => $projectId, ':month' => $month ]); if ($stmt->rowCount() > 0) { $response['success'] = true; unset($response['error']); } else { $response['error'] = 'No record found to update.'; } } catch (PDOException $e) { $response['error'] = 'Database error: ' . $e->getMessage(); } } else { $response['error'] = 'Missing required fields.'; } } echo json_encode($response);