Re: Random number Question
| From: | Dan Koken | Date: | Mon, 29 Apr 2002 15:36:22 +0000 |
| Subject: | Re: Random number Question | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-95178@lists.php.net to get a copy of this message | ||
Try something like this and see if it works???
====================================================
<?
$another = 'a';
if (isset($guess)) $another = 'another';
echo "
<form action='number.php' method='post'>
<BR>
The computer has picked $another number between 1 and 10.<BR>
Guess the number and you win!<BR>
<BR>
Enter your guess:
<input type='text' size='3'>
<INPUT TYPE='submit' VALUE='Submit my number' NAME='guess'>
</form>";
if (isset($guess))
{
srand((double)microtime()*1000000);
$number = rand(1,10);
echo "The number is: $number<BR>";
if ($guess == $number)
{
echo '<BR>You have won!';
}else{
echo "<BR>Sorry that wasn't the answer";
}
}
?>
=================================================================
Jennifer Downey wrote:
Hi all,
I having a hard time understanding why this won't work. I have a form which
is suppose to pass the guess to the script. Here it is:
the form is guess.php:
<form action="number.php" method="post">
The computer has picked a number between 1 and 10. Guess the number and you
win!<BR>
Enter your guess:
<input type="text" size="3">
<INPUT TYPE="submit" VALUE="Submit my number" NAME="guess">
</form>
The script is number.php:
<?php
echo"The number is:";
srand((double)microtime()*1000000);
$number = rand(1,10);
echo $number;
if($guess = = $number) {
echo"<BR>You have won!";
}else{
print("<BR>Sorry that wasn't the answer");
}
?>
Any help would be appreciated.
Thanks in advance
Jennifer Downey