-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
98 lines (94 loc) · 4.88 KB
/
index.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
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
session_unset();
session_start();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Wisielec :)</title>
<link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css'>
<link rel='stylesheet' href='https://fonts.googleapis.com/css?family=Muli'>
<link rel="stylesheet" href="./style.css">
</head>
<body>
<div class="pt-5">
<div class="container">
<div class="row">
<div class="mx-auto">
<h1 class="text-center pb-5">Wisielec :)</h1>
<div class="card card-body">
<form id="submitForm" method="post"><input
type="hidden" name="_csrf">
<div class="form-group required">
<label for="username">Nazwa użytkownika</label>
<input type="text" class="form-control" id="username" maxlength="20" required="" name="username"
value="">
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="inlineRadioOptions" id="inlineRadio1"
value="option1" checked>
<label class="form-check-label" for="inlineRadio1">Łatwy</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="inlineRadioOptions" id="inlineRadio2"
value="option2">
<label class="form-check-label" for="inlineRadio2">Średni</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="inlineRadioOptions" id="inlineRadio3"
value="option3">
<label class="form-check-label" for="inlineRadio3">Trudny</label>
</div>
<div class="form-group pt-3 mb-1">
<input class="btn btn-block" type="submit" name="graj" value="Graj">
<?php if(isset($_POST['graj'])){if(!preg_match('/^[A-Za-z]+[A-Za-z0-9]*$/', $_POST['username'])){
echo "Zły nick! Usuń spację, znaki specjalne i nie używaj samych cyfr!<br>";
}
else{
$_SESSION['username']=$_POST['username'];
$_SESSION['poziom']=$_POST['inlineRadioOptions'];
header("Location: gra.php");
}}?>
</div>
</form>
</div>
<h1 class="text-center mt-5 pb-1">Ranking</h1>
<h5 class="text-center mt-1 pb-1">Top 10</h5>
<div class="card card-body mt-5 mb-5">
<?php
mysqli_report(MYSQLI_REPORT_OFF);
$dbhost = '';
$dbuser = '';
$dbpass = '';
$dbname = '';
$mysqli = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
if($mysqli->connect_errno ) {
printf("Nie udało sie wczytać rankingu: %s<br>", $mysqli->connect_error);
exit();
}
$wynik=$mysqli->query("SELECT * FROM Ranking ORDER BY Czas ASC;");
echo "<table><tr><th>Miejsce</th><th>Nazwa</th><th>Czas</th><th>Poziom</th></tr>";
if ($wynik->num_rows > 0) {
$x=1;
while($row = $wynik->fetch_assoc()) {
if($x==11){
break;
}
echo "<tr><td>".$x.". </td><td>".$row['Nazwa']."</td><td>".$row['Czas']."</td><td>".$row['Poziom']."</td></tr>";
$x++;
}
echo "</table>";
}
else {
echo "<tr><td>Brak rekordów.</td></tr>";
}
$mysqli->close();
?>
</div>
</div>
</div>
</div>
</div>
</body>
</html>