* licensed under AGPLv3-or-later; see LICENSE.md for more information */ header('Content-Type: application/json; charset=UTF-8'); try { $pdo = new PDO("mysql:host=127.0.0.1;dbname=hitlerclicker", "root", "aA1234Aa"); } catch(PDOException $e) { die('{ "status": "database offline" }'); }; $wrkarr = []; $ifarr = [ "team" ]; $postjson = json_decode(file_get_contents('php://input'), true); foreach ($ifarr as $i): if (isset($postjson[$i])): $newarr = [ "$i" => "$postjson[$i]", ]; $wrkarr = array_merge($wrkarr, $newarr); endif; endforeach; if (!isset($wrkarr["team"]) || trim($wrkarr["team"]) == ""): die('{ "status": "team was not provided.\ncould not add a click." }'); else: $query = $pdo->prepare("SELECT team FROM stats WHERE team LIKE ?"); $query->execute([$wrkarr["team"]]); $found = $query->fetch(PDO::FETCH_ASSOC); if ($found): $query = $pdo->prepare("SELECT team, clicks, fromanon FROM stats WHERE team LIKE ?"); $query->execute([$found["team"]]); $found = $query->fetch(PDO::FETCH_ASSOC); $newteamclicks = $found["clicks"] + 1; $newanonclicks = $found["fromanon"] + 1; $query = $pdo->prepare("UPDATE stats SET clicks = :clicks , fromanon = :fromanon WHERE stats.team = :team"); $query->execute([ "clicks" => "$newteamclicks", "fromanon" => "$newanonclicks", "team" => "$found[team]", ]); die("{ \"status\": \"success\", \"nac\": \"$newanonclicks\" \"ntc\": \"$newteamclicks\" }"); else: die('{ "status": "team does not exist in the database." }'); endif; endif; echo '{ "status": "online" }'; ?>