If you read anything from my last question you know I am working on a dice roller and I am on to the next step.

Stage one was just trying to figure out how to get a random, and I finally got the to work. I can now roll and sided die i want once and it prints the result...

Stage two is getting the program to rolls multiples of the same die and print all the results. I thought I could do it with a "while" statement and this is what I got from the server:

"500 Internal Server Error:
The server encountered an internal error or misconfiguration and was unable to complete your request."

I have no idea what this means. I am trying to do this all one step at a time and get it right and I am trying to do this on my own. I only questions after I have exhausted all, what I think, are my only options. Please do not think I am trying to have you all build me a program for free :)

Here's what I have for stage two that is getting me the error, any help you all could give would be great.

<?
$i=$_POST["hmany"];

while($i>=1);
	{
	$rand=mt_rand(1,$_POST["dice"]);
	echo "You rolled a $rand";
	$i--;
	}
?>

Recommended Answers

All 3 Replies

get rid of the semicolon ";" after while($i>=1).... but the way in which you are doing the while loop will cause an infinate loop

Well, I took it out and it worked. The good news is is that it didn't make an infinite loop, but all the "random" numbers are coming up the number 1.... back to the drawing board :)

Thanks Auzzie

you could use a for loop rather than a while statement. For example:

$howMany=$_POST["hmany"];

for($i=0;$i<=$howMany;$i++)
{
     $rand=mt_rand(1,$_POST["dice"]);
     echo "You rolled a $rand";	
}

if your numbers are all coming up '1', that probably means the value of $_POST["dice"] is empty or '1'. Check that you are passing it correctly.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.