· 9 years ago · Apr 07, 2017, 11:38 AM
1<html>
2
3<head>
4<link rel="stylesheet" type="text/css" href="style.css">
5<title>Hello world</title>
6</head>
7
8<body>
9
10<?php
11$serverName = "localhost";
12$userName = "jesper2";
13$password = "123";
14$dbName = "jesperi";
15$tableName = "spaceshooter";
16$secretKey ="SuperSecretPasswordKey";
17
18$name = $_POST['name'];
19$score = $_POST['score'];
20$receivedHash = $_POST['hash'];
21
22if($name != null)
23{
24
25
26
27//create connection
28
29$db = new mysqli($serverName, $userName, $password, $dbName);
30
31//Check connection
32
33if($db->connect_error)
34{
35 die("Connection failed: " . $db->connect_error);
36}
37else
38 echo "Connection successful! \n";
39
40$hash = md5($name . $score . $secretKey); //the correct hash
41
42//Check Validation (is the received hash correct?)
43if($hash == $receivedHash)
44{
45$sql = "INSERT INTO " . $tableName . " (Name, Score) VALUES ('" . $name . "','" . $score . "')";
46
47//Query the database
48
49if($db->query($sql) === true)
50{
51 echo "New record created successfully! \n";
52 echo $name . " with the score: " . $score;
53}
54else echo "Error: " . $sql . "\n" . $db->error;
55}
56$db->close();
57
58}
59?>
60
61
62
63</body>
64
65</html>