<?php
$host = 'localhost';
$dbname = 'users';
$username = 'pail';
$password = 'password';

try {
  // Create a new PDO instance
  $pdo = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);

  // Set PDO error mode to exception
  $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

  // Get the score, player name, and current time from the request
  $score = $_POST['score'];
  $name = $_POST['playerName'];
  $currentTime = date('Y-m-d H:i:s'); // Current time in MySQL datetime format

  // Prepare the SQL query
  $query = $pdo->prepare("INSERT INTO uzivatelia (score, name, time) VALUES (:score, :name, :time)");

  // Bind the parameters
  $query->bindParam(':score', $score);
  $query->bindParam(':name', $name);
  $query->bindParam(':time', $currentTime);

  // Execute the query
  $query->execute();

  echo "Score saved to the database";
} catch (PDOException $e) {
  echo "Error saving score to the database: " . $e->getMessage();
}
?>
