<?php
if (!isset($_SESSION)) {
session_start();
}
require '../mysqlHandler.php';
include '../t/headSectionUnclosed.php';
echo '</head><body>';
include '../t/userBar.php';
$score = $_SESSION['user_score'];
$user_id = 0;
openConnection();
if ($score > 0) {
if (!empty($_COOKIE['user'])) {
$result = executeQuery('select user_id from user where username ="' . $_COOKIE['user'] . '"');
}
while ($row = mysql_fetch_array($result)) {
$user_id = $row['user_id'];
}
if ((!empty($user_id)) && $user_id > 0) {
$sql = "insert into user_score (user_id, score) values (" . $user_id . ", " . $score . ")";
$result = executeQuery($sql);
if ($result) {
echo '<h1>Congrats, ' . $_COOKIE['user'] . '! You scored ' . $score . ' points.</h1>';
echo '<em>Saved to scores list</em> <br><br>';
echo '<a href="index.php" id="button-link">Play again</a>';
echo ' ';
echo '<a href="highscores" id="button-link">View high scores</a>';
} else {
echo "Couldn't insert result using this SQL: " . $sql . "<br>";
}
}
} else {
echo "<h1><em>No new scores to enter for user " . $_COOKIE['user'] . "</em></h1>";
}
if (isset($_SESSION)) {
session_destroy();
}
closeConnection();
?>
</body>
</html>