Okay, I have this assignment to make a guessing game in PHP, that uses sessions to store a random number between 0 and 100, along with the number of guesses the user has attempted. Each time the user guesses wrong, the number of times the user has guessed should be displayed. I have some of the code so far, but it isn’t working, any help would be greatly appreciate…I am sooo frustrated right now, ive been looking at this thing almost all day for a week and i can’t figure out what the problem is.
Here’s my code:
This is game.php
[php]<?php
session_start();
if (!isset($_SESSION[“randNum”])) {
$_SESSION["randNum"]=rand(1,100);
}
$randNum=intval($_SESSION[“randNum”]);
?>
This is game_check.php
[php]<?php
session_start();
$_SESSION[“randNum”] = $_POST[“randNum”];
$userGuess=$_POST[“userGuess”];
if (isset($randNum)) {
if ($userGuess<$randNum) {
echo “You guessed too low!”;
}
if ($userGuess>$randNum) {
echo “You guessed too high!”;
}
if ($userGuess==$randNum) {
echo “Congratulations You’re right!!!”;
unset($_SESSION[“randNum”]);
}
}
else {
echo “Uh oh”;
}
?>[/php]