-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscore.php
More file actions
54 lines (44 loc) · 1.46 KB
/
score.php
File metadata and controls
54 lines (44 loc) · 1.46 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
$connect = mysqli_connect(
'db', // service name
'php_docker', // username
'password', // password
'php_docker' // db table
);
if ($connect->connect_errno) {
die("Baglanti hatasi: " . $connect->connect_error);
}
$d = json_decode(file_get_contents("php://input"), true);
$uid = $d['uid'];
$skor = $d['skor'];
// Kullanıcının ID'sine ait skoru kontrol et
$Scoresql = "SELECT * FROM game WHERE user_id = '$uid'";
$result = $connect->query($Scoresql);
if ($result->num_rows > 0) {
// Kullanıcının daha önce skoru var, yeni skor eski skordan büyük mü kontrol et
$row = $result->fetch_assoc();
$Scoreo = $row['highest_score'];
if ($skor > $Scoreo) {
// Yeni skor eski skordan büyük, güncelleme işlemi yap
$ScoreUpdatesql = "UPDATE game SET highest_score = '$skor' WHERE user_id = '$uid'";
if ($connect->query($ScoreUpdatesql) === TRUE) {
echo "Skor guncellendi";
} else {
echo "Hata: " . $connect->error;
}
} else {
echo "Yeni skor eski skordan kucuk veya esit";
}
} else {
// Kullanıcının daha önce skoru yok, yeni skoru ekle
$ScoreInsertsql = "INSERT INTO game (`user_id`, `highest_score`) VALUES ('$uid', '$skor')";
if ($connect->query($ScoreInsertsql) === TRUE) {
echo "Skor eklendi";
} else {
echo "Hata: " . $connect->error;
}
}
$connect->close();
error_reporting(E_ALL);
ini_set('display_errors', 1);
?>