trouble with another beginner example
Posted: Sun May 31, 2009 9:52 pm
im trying to make a program that prints out various amouns of random dice like so:
when i run it it doesnt do anything. i just get a white page. my editor shows some output but it is still incorrect. it shows the background, some text from my code and then a text box and more text from my code. i.e. it kind of prints the form from howMany().
Can someone help me? thanks
Code: Select all
<html>
<head>
<title>Create 4 10 or 20 random dice</title>
</head>
<body bgcolor="#ffcc99">
<h3>Creating 4 random dice</h3>
<?php
global $numDice;
if(empty($numDice)){
print howManyDice();
} else {
switch($numDice){
case 4:
createRandDice();
createRandDice();
createRandDice();
createRandDice();
break;
case 10:
createRandDice();
createRandDice();
createRandDice();
createRandDice();
createRandDice();
createRandDice();
createRandDice();
createRandDice();
createRandDice();
createRandDice();
break;
case 20:
createRandDice();
createRandDice();
createRandDice();
createRandDice();
createRandDice();
createRandDice();
createRandDice();
createRandDice();
createRandDice();
createRandDice();
createRandDice();
createRandDice();
createRandDice();
createRandDice();
createRandDice();
createRandDice();
createRandDice();
createRandDice();
createRandDice();
createRandDice();
break;
default:
createRandDice();
break;
}
}
function createRandDice(){
$rand = rand(1,6);
print <<<HERE
<img src="$randDie.jpg"
alt="$rand"
height ="100"
width ="100">
HERE;
}
function howManyDice(){
$output = <<<HERE
Enter 4, 10, or 20:
<form method ="post">
<input type ="text"
name ="$numDice"
value ="">
<input type ="submit"
value ="Make dice">
</form>
HERE;
return $output;
}
?>
</body>
</html>
Can someone help me? thanks