SpeedCrazy Posted April 12, 2011 Posted April 12, 2011 (edited) Hey guys, I have an odd PHP problem, <?php session_start(); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtm11/DTD/xhtml11-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>rollDie.php</title> </head> <body> <h1>Roll Dice</h1> <h2>Uses Functions</h2> <?php function init(){ global $count; global $total; if(isset($_SESSION["count"])){ $count = $_SESSION["count"]; $count++; $SESSION["count"] = $count; } else { $_SESSION["count"]= 1; $_SESSION["total"]= 0; $count= 1; } //end if }//end init function rollDie(){ global $total; $roll = rand(1,6); $image = "die$roll.jpg"; print<<< HERE <img src = "$image" alt = "roll: $roll" /> HERE; $total = $_SESSION["total"]; $total+= $roll; $_SESSION["total"]= $total; } // end rollDie init(); rollDie(); print " <p>Rolls: $count</p> \n"; print " <p>Total: $total</p> \n"; ?> </body> </html> With that code i get this. Which is fine, except the 'Rolls:' stops at 2. I cant find any thing that deviates from my textbook but it may just be im tired. Any help would be appreciated. Thanks, Speed Edited April 12, 2011 by SpeedCrazy Share this post Link to post Share on other sites More sharing options...
SpeedCrazy Posted April 12, 2011 Posted April 12, 2011 I think i need to sleep. I forgot the _ when calling the session variable. $SESSION["count"] = $count; Share this post Link to post Share on other sites More sharing options...
flareback Posted April 12, 2011 Posted April 12, 2011 You left off the underscore between the $ and SESSION in $SESSION["count"] = $count; in your if statement in the init functions Share this post Link to post Share on other sites More sharing options...
jjjrmy Posted April 12, 2011 Posted April 12, 2011 (edited) Upload it somewhere so I can test it out. I have a hunch. I knew it was something with that line. But I didn't expect it to be a spelling mistake. Edited April 12, 2011 by jjjrmy Share this post Link to post Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now