Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. <?php
  2. if (!isset($_SESSION)) {
  3.     session_start();
  4. }
  5.  
  6. require '../mysqlHandler.php';
  7.  
  8. include '../t/headSectionUnclosed.php';
  9. echo '</head><body>';
  10. include '../t/userBar.php';
  11.  
  12. $score = $_SESSION['user_score'];
  13. $user_id = 0;
  14.  
  15. openConnection();
  16.  
  17. if ($score > 0) {
  18.     if (!empty($_COOKIE['user'])) {
  19.         $result = executeQuery('select user_id from user where username ="' . $_COOKIE['user'] . '"');
  20.     }
  21.    
  22.     while ($row = mysql_fetch_array($result)) {
  23.         $user_id = $row['user_id'];
  24.     }
  25.  
  26.  
  27.     if ((!empty($user_id)) && $user_id > 0) {
  28.         $sql = "insert into user_score (user_id, score) values (" . $user_id . ", " . $score . ")";
  29.         $result = executeQuery($sql);
  30.        
  31.         if ($result) {
  32.             echo '<h1>Congrats, ' . $_COOKIE['user'] . '! You scored ' . $score . ' points.</h1>';
  33.             echo '<em>Saved to scores list</em> <br><br>';
  34.             echo '<a href="index.php" id="button-link">Play again</a>';
  35.             echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  36.             echo '<a href="highscores" id="button-link">View high scores</a>';
  37.         } else {
  38.             echo "Couldn't insert result using this SQL: " . $sql . "<br>";
  39.         }
  40.     }
  41. } else {
  42.     echo "<h1><em>No new scores to enter for user " . $_COOKIE['user'] . "</em></h1>";
  43. }
  44.  
  45. if (isset($_SESSION)) {
  46.     session_destroy();
  47. }
  48. closeConnection();
  49. ?>
  50. </body>
  51. </html>