From d4b297598e2ffe6890ef4890cba884f875a25c63 Mon Sep 17 00:00:00 2001 From: hitlerrip Date: Tue, 29 Jul 2025 20:51:12 +0200 Subject: click api added the api that increments all counters --- backend/click.php | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 backend/click.php (limited to 'backend') diff --git a/backend/click.php b/backend/click.php new file mode 100644 index 0000000..7b8a067 --- /dev/null +++ b/backend/click.php @@ -0,0 +1,62 @@ + "$postjson[$i]", + ]; + $wrkarr = array_merge($wrkarr, $newarr); + endif; +endforeach; + +if (!isset($wrkarr["token"]) || trim($wrkarr["token"]) == ""): + die('{ "status": "token was not provided.\ncould not add a click." }'); +else: + + $query = $pdo->prepare("SELECT token, team, clicks FROM users WHERE token LIKE ?"); + $query->execute([$wrkarr["token"]]); + $found = $query->fetch(PDO::FETCH_ASSOC); + if ($found): + + $newuserclicks = $found["clicks"] + 1; + + $query = $pdo->prepare("UPDATE users SET clicks = :clicks WHERE users.token = :token"); + $query->execute([ + "clicks" => "$newuserclicks", + "token" => "$wrkarr[token]", + ]); + + $query = $pdo->prepare("SELECT team, clicks FROM stats WHERE team LIKE ?"); + $query->execute([$found["team"]]); + $found = $query->fetch(PDO::FETCH_ASSOC); + + $newteamclicks = $found["clicks"] + 1; + + $query = $pdo->prepare("UPDATE stats SET clicks = :clicks WHERE stats.team = :team"); + $query->execute([ + "clicks" => "$newteamclicks", + "team" => "$found[team]", + ]); + + die("{ \"status\": \"success\", \"nuc\": \"$newuserclicks\", \"ntc\": \"$newteamclicks\" }"); + + + else: + die('{ "status": "user does not exist in the database." }'); + endif; + +endif; + +echo '{ "status": "online" }'; + +?> -- cgit v1.2.3