<?php
$mysql_handle = mysql_connect($dbhost, $dbuser, $dbpass)
or die("Error connecting to database server");
mysql_select_db($dbname, $mysql_handle)
or die("Error selecting database: $dbname");
?>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
</head>
<body>
<center>
<h2>Sorry, it looks like you lost...</h2>
<h3>Your score was: <?php echo $_SESSION["score"] ?>! If this was your highest score, it has been saved.</h3>
<button id="restartButton" type="button" onclick="restart()" name="restart" class="btn btn-info">Restart</button>
</center>
</body>
</html>
<script>
//when restart is clicked
function restart()
{
header("http://web.engr.oregonstate.edu/~chathamb/CodingPractice/ImprovedPongGame/game.php");
}
</script>
<?php
mysql_close($mysql_handle);
?>
This is my code in gameOver.php and I can't seem to figure out why my $_SESSION["score"] is not being maintained properly. My first time through testing, it displayed 4 correctly, now I'm having some issues even printing out the echo and it will not reset after the restart() function that executes the header redirect.
From my research, I think the issue revolves around the header() redirect, but I can't seem to figure it out. I tried an AJAX workaround but it didn't work.
And yes, session_start(); is at the very top of my code on my game.php code. The game.php code is pretty long and kind of messy so I will save you all from the pain of seeing that.