Advertisement
Coltmannnen

Untitled

Apr 7th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  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.  
  22. if($name != null)
  23. {
  24.  
  25.  
  26.  
  27. //create connection
  28.  
  29. $db = new mysqli($serverName, $userName, $password, $dbName);
  30.  
  31. //Check connection
  32.  
  33. if($db->connect_error)
  34. {
  35. die("Connection failed: " . $db->connect_error);
  36. }
  37. else
  38. echo "Connection successful! \n";
  39.  
  40. $hash = md5($name . $score . $secretKey); //the correct hash
  41.  
  42. //Check Validation (is the received hash correct?)
  43. if($hash == $receivedHash)
  44. {
  45. $sql = "INSERT INTO " . $tableName . " (Name, Score) VALUES ('" . $name . "','" . $score . "')";
  46.  
  47. //Query the database
  48.  
  49. if($db->query($sql) === true)
  50. {
  51. echo "New record created successfully! \n";
  52. echo $name . " with the score: " . $score;
  53. }
  54. else echo "Error: " . $sql . "\n" . $db->error;
  55. }
  56. $db->close();
  57.  
  58. }
  59. ?>
  60.  
  61.  
  62.  
  63. </body>
  64.  
  65. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement