<?php
include 'db.php';

$id = intval($_POST['id'] ?? 0);
$value = ($_POST['value'] ?? '') === '1' ? '1' : ($_POST['value'] ?? '');

if ($id > 0) {
    $stmt = $conn->prepare("UPDATE settings SET value = ? WHERE id = ?");
    if (!$stmt) {
        echo "Prepare failed: " . $conn->error;
        exit;
    }
    $stmt->bind_param("si", $value, $id);
    if ($stmt->execute()) {
        echo "success";
    } else {
        echo "Execute failed: " . $stmt->error;
    }
    $stmt->close();
} else {
    http_response_code(400);
    echo "invalid id: $id, value: $value";
}
