counter problem
| From: | Anthony Ritter | Date: | Sat, 04 Jan 2003 23:40:40 +0000 |
| Subject: | counter problem | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-130263@lists.php.net to get a copy of this message | ||
The following script is found in Matt Zandstra's book on PHP (Sams) on page
160.
He's explaining forms with PHP and has hard coded a value - 42.
He also is explaining a hidden fleld where the user can submit the number
and each time the user hits submit in the formbox, the counter will register
the total number of guesses.
However, after running this script and submitting the number, I get:
Guess number: 0 \\\"\\
submit again and...
Guess number: 0 \\\\\\""\\\\, etc...
instead of:
Guess number: 1
Guess numver : 2
etc...
Thanking all in advance.
Tony Ritter
..........................................................
<?
$numtoguess=42;
$num_tries=(isset($num_tries)) ? $num_tries++ : 0;
$message="";
if(!isset($guess))
$message="Welcome to the guessing machine";
elseif ($guess<$numtoguess)
$message="Your guess was too low.";
elseif ($guess>$numtoguess)
$message="Your guess was too high.";
else
$message="That is the correct number.";
$guess=(int)$guess;
?>
<HTML>
<BODY>
<H1>
<? print $message ?>
</H1>
Guess number: <?print $num_tries?>
<FORM METHOD="post">
Type your guess here:<BR>
<INPUT TYPE ="text" NAME="guess" VALUE="<?print $guess?>">
<INPUT TYPE ="hidden" NAME="num_tries" VALUE=<? print
$num_tries?>">
<INPUT TYPE="submit" VALUE="submit it!">
</FORM>
</BODY>
</HTML>