-
Notifications
You must be signed in to change notification settings - Fork 1
/
handler_blitz.php
26 lines (22 loc) · 1.12 KB
/
handler_blitz.php
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 header("Content-type: text/html; charset=utf-8"); ?>
<?php
$link = mysqli_connect("localhost", "db", "password");
if (!$link) {
die('Ошибка подключения (' . mysqli_connect_errno() . ') '
. mysqli_connect_error());
}
mysqli_set_charset($link, "utf8");
mysqli_select_db($link, "db");
$data = mysqli_query($link, "SELECT * FROM `blitz` WHERE `id` = '$_POST[id]'");
$row = mysqli_fetch_array($data, MYSQLI_ASSOC);
if ($row) {
if ($row['score'] < $_POST[score]) {
mysqli_query($link, "UPDATE `blitz` SET `score` = '$_POST[score]', `time` = '$_POST[time]' WHERE `id` = '$_POST[id]'");
} else if ($row['score'] == $_POST[score] and $row['time'] > $_POST[time]) {
mysqli_query($link, "UPDATE `blitz` SET `time` = '$_POST[time]' WHERE `id` = '$_POST[id]'");
}
} else {
mysqli_query($link, "INSERT INTO `blitz` (`score`, `time`, `id`, `name`, `photo_url`) VALUES ('$_POST[score]', '$_POST[time]', '$_POST[id]', '$_POST[name]', '$_POST[photo_url]')") or die(mysqli_error($link));
}
mysqli_close($link);
?>