Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <link rel="stylesheet" type="text/css" href="style.css">
- <title>Hello world</title>
- </head>
- <body>
- <?php
- $serverName = "localhost";
- $userName = "jesper2";
- $password = "123";
- $dbName = "jesperi";
- $tableName = "spaceshooter";
- $secretKey ="SuperSecretPasswordKey";
- $name = $_POST['name'];
- $score = $_POST['score'];
- $receivedHash = $_POST['hash'];
- if($name != null)
- {
- //create connection
- $db = new mysqli($serverName, $userName, $password, $dbName);
- //Check connection
- if($db->connect_error)
- {
- die("Connection failed: " . $db->connect_error);
- }
- else
- echo "Connection successful! \n";
- $hash = md5($name . $score . $secretKey); //the correct hash
- //Check Validation (is the received hash correct?)
- if($hash == $receivedHash)
- {
- $sql = "INSERT INTO " . $tableName . " (Name, Score) VALUES ('" . $name . "','" . $score . "')";
- //Query the database
- if($db->query($sql) === true)
- {
- echo "New record created successfully! \n";
- echo $name . " with the score: " . $score;
- }
- else echo "Error: " . $sql . "\n" . $db->error;
- }
- $db->close();
- }
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement