Reputation: 13
I'm trying to build a word guessing game, where people input their name, and they are given 5 tries to guess a game (The first letter is free).
I had the game working all fine and dandy, but I decided to add a ''starting'' page, where people can enter their names, and where the random word is already pre-chosen for the actual game page. (It rand's a word from a 20-word array)
But now for some reason, everytime I have people enter the game, it immediately skips past the game screen and immediately jumps to the win-screen... It's supposed to show the name and the winning word on said screen, but it doesn't show either of them, it's just blank.
So i'm assuming that for some reason, the two variables aren't being remembered after you enter the name, as such the game comparing null to null and the game being ''won''...
Obviously, this shouldn't happen. A word should be picked out of the array, and put in a session_variable. Same goes with the name that you input into the form.
Seeing as it's a three-page PHP script, I will put links to Hastebin rather than post snippets here. Sorry for that in advance, but I think it'll work better...
Start Screen: http://hastebin.com/orisazubis.xml
Game Screen: http://hastebin.com/akuzekawil.php
Upvotes: 0
Views: 65
Reputation: 17289
replace $session
and $_session
to $_SESSION
everywhere
in your:
http://hastebin.com/orisazubis.xml change:
if($random == null) {
$session = $woorden[rand(0,19)];
}
to
if($random == null) {
$_SESSION['random'] = $woorden[rand(0,19)];
}
and finally in file http://hastebin.com/akuzekawil.php
change :
$random = $_session['random'];
to
if (isset($_SESSION['random'])) {
$random = $_SESSION['random'];
}else{
$random=null;
}
check here also:
$_session['naam'] = $_POST['naam'];
change to:
if (isset($_POST['naam']) && !empty($_POST['naam']){
$_SESSION['naam'] = $_POST['naam'];
} else {
$_SESSION['naam'] = null;
}
update line:
if($random == $testen){
to
if(!empty($testen) && $random == $testen){
if I got right your logic
Upvotes: 0
Reputation: 78994
I didn't look through all of that but why not try $_SESSION
since that's what PHP populates? You do know that PHP variables are case sensitive right?
Upvotes: 1