| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| On Saturday 13 March 2010 11:54, 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: It's no good just telling us it doesn't work. You need to tell us what happens when you run it. Error messages? Blank screen? -- Jason Wong -> Gremlins Associates -> www.gremlins.com.hk /* "355/113 -- Not the famous irrational number PI, but an incredible simulation!" */ |
|
#2
| |||
| |||
| Try Now: <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" name="guess" value="" size="3"> <INPUT TYPE="submit" VALUE="Submit my number" NAME="submit"> </form> -----Original Message----- From: Jennifer Downey [mailto:jendowney@attbi.com] Sent: Saturday, March 13, 2010 9:25 AM To: php-general@lists.php.net Subject: [php] Random number Question 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php |
|
#3
| |||
| |||
| In article <20020313035421.28517.qmail@pb1.pair.com>, Jennifer Downey wrote: > <input type="text" size="3"> > <INPUT TYPE="submit" VALUE="Submit my number" NAME="guess"> > you've got the "Name" attribute attached to the wrong INPUT element: <INPUT type="text" size="3" name="guess"> <INPUT type="submit" value="Submit my number"> > if($guess = = $number) { > incorrect syntax here. that should be: if ($guess == $number) { better would be: if (trim($guess) == $number { this will assure that there's no whitespace in $guess -- Rgds Ralph |
|
#4
| |||
| |||
| $guess = = $number is wrong. You should write: $guess == $number Regards, Hiroshi Ayukawa http://hoover.ktplan.ne.jp/kaihatsu/...x.php?type=top |
|
#5
| |||
| |||
| actually if (intval($guess) == $number { would be more acuate then the trim ( ) you would eliminate all alpha characters and floating points saying it has to be a whole integer.... Joel "Ralph Friedman" <ralph@friedman-net.com> wrote in message news:VA.00000005.0285e606@friedman-net.com... > In article <20020313035421.28517.qmail@pb1.pair.com>, Jennifer Downey wrote: > > > <input type="text" size="3"> > > <INPUT TYPE="submit" VALUE="Submit my number" NAME="guess"> > > > you've got the "Name" attribute attached to the wrong INPUT element: > > <INPUT type="text" size="3" name="guess"> > <INPUT type="submit" value="Submit my number"> > > > if($guess = = $number) { > > > incorrect syntax here. that should be: > if ($guess == $number) { > > better would be: > > if (trim($guess) == $number { > > this will assure that there's no whitespace in $guess > > -- > Rgds > Ralph > > |
|
#6
| |||
| |||
| 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 > > > |
|
#7
| |||
| |||
| OOPS! You are right on.. I noticed my error after I sent it. The name='guess' was on the input.?? Daaa! it's Monday .. OK!! This should work: ================================================== = <? $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' NAME='guess'> <INPUT TYPE='submit' VALUE='Submit my number'> </form>"; if (isset($guess)) { srand((double)microtime()*1000000); $number = floor(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"; } ?> |
|
#8
| |||
| |||
| 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 |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.