-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.php
More file actions
26 lines (21 loc) · 854 Bytes
/
Copy pathgame.php
File metadata and controls
26 lines (21 loc) · 854 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?php
if (isset($_GET['name']) && isset($_GET['score']) && isset($_GET['level']))
{
$name = $_GET['name'];
$score = $_GET['score'];
$level = $_GET['level'];
$sql = "INSERT INTO table_records (name, score, level) VALUES (:name, :score, :level)";
$dbh = new PDO('mysql:dbname=js_test;host=localhost', 'root', '');
$sth = $dbh->prepare($sql);
$sth->execute([':name' => $name, ':score' => $score, ':level' => $level]);
echo 'Игра завершена. Вы можете посмотреть таблицу рекордов';
}
if (isset($_GET['records']))
{
$sql = "SELECT name, score, level FROM table_records ORDER BY score DESC";
$dbh = new PDO('mysql:dbname=js_test;host=localhost', 'root', '');
$sth = $dbh->prepare($sql);
$sth->execute();
$res = $sth->fetchAll();
echo json_encode($res);
}