-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata.php
More file actions
63 lines (58 loc) · 2.09 KB
/
data.php
File metadata and controls
63 lines (58 loc) · 2.09 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
55
56
57
58
59
60
61
62
63
<?php
//Mysql connection data
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "adveisordb";
//get data with HTTP POST method
$connection = test_input($_POST['connection']);
//test user input for security purposes
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
if($connection == "set"){
$game_data = test_input($_POST['game_data']);
$game_id = test_input($_POST['game_id']);
// Create connection with DB
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
//Insert data into DB
$sql = "INSERT INTO current_game (game_data, game_id)
VALUES ('$game_data',$game_id)";
//Check if the registration is successful
if ($conn->query($sql) === TRUE) {
echo "ok";
} else {
echo "OOPS :C Es ist ein unerwarteter Fehler aufgetreten: " . $sql . "<br>" . $conn->error;
}
//close connection with DB
$conn->close();
}elseif ($connection == "get") {
//create connection with target Database
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM `current_game` WHERE id=(SELECT MAX(id) FROM `current_game`)";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output each row data
while($row = $result->fetch_assoc()) {
$game_data = $row["game_data"];
$game_id = $row["game_data"];
$reg_date = $row["reg_date"];
echo $row["game_data"] . "!" . $row["game_id"]. "!" . $row["reg_date"] ;
}
} else {
echo "0 results";
}
$conn->close();
}
?>