Jump to content
Sign in to follow this  
SpeedCrazy

[SOLVED]PHP unkown error.

Recommended Posts

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 by SpeedCrazy

Share this post


Link to post
Share on other sites

:mfp: 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

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

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 by jjjrmy

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...