<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");

include 'conexion.php';

$table = 'users';
// Get the JSON input
$getJson = file_get_contents('php://input');
$json = json_decode($getJson);
$username = $json->username;
$points = $json->points;
$result = $connect->query("UPDATE " . $table . " SET point = $points + point, spin_chance = spin_chance - 1 WHERE username LIKE '$username';");

if ($result) {
    $response = array(
        'error' => false,
        'message' => null
    );
} else {
    $response = array(
        'error' => true,
        'message' => 'Failed to update points'
    );
}
header('Content-Type: application/json');
echo json_encode($response);
