-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_last_trivia.php
34 lines (33 loc) · 1.18 KB
/
get_last_trivia.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
<?php
header('Access-Control-Allow-Origin: *');
header('Content-Type: text/plain; charset=UTF-8;');
if($_GET["secret"] === ",yD:n]kDu7Z?zjn<") {
$servername = "localhost";
$username = "tekntehf_trivias_user";
$password = "Fo3A4QZ)*s+d";
$dbname = "tekntehf_trivias";
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$lang_change = "SET NAMES utf8mb4";
if (!mysqli_query($conn, $lang_change)) {
//echo "Error: " . $sql . "<br>" . mysqli_error($conn);
echo "There was an error. Please try again later.";
}
$sql = "SELECT name, time, chat, total FROM trivia_data ORDER BY id DESC LIMIT 1";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo "{$row['chat']}\n{$row['name']}\n{$row['time']}\n{$row['total']}";
}
} else {
//echo "Found 0 last trivias.";
echo "There was an error. Please try again later.";
}
$conn->close();
} else {
echo "The provided secret key is wrong or you didn't even provide a secret key.";
}
?>