number of tries does not increment in the PHP number-guessing game

baphorgeabupe

New Member
The PHP script below is for a number-guessing game. A hidden field is used to store the number of guesses, represented by the variable $tries. No matter how I tried, the number of guess ($tries) never increment. Could someone tell me what is wrong with the code please?Maria\[code\]<?php$num=21;$tries=(isset($_POST['guess'])) ? $tries+1: 0;if (!isset($_POST['guess'])) { $message="Welcome to the Guessing Game!";} elseif (!is_numeric($_POST['guess'])) { $message="You need to type in a number.";} elseif ($_POST['guess']==$num) { $message="You WON 1 million point!";} elseif ($_POST['guess']>$num) { $message="Try a smaller number";} else { $message="Try a bigger number";}?><!DOCTYPE html><html><head><title>Guessing Game</title></head><body><h1><?php echo $message; ?></h1><p><strong>Guess number: </strong><?php echo $tries; ?></p><form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"><p><label for="guess">Type your guess here:</label><br/><input type="text" id="guess" name="guess" /><input type="hidden" name="tries" value="http://stackoverflow.com/questions/15755246/<?php echo $tries; ?>"/></p><button type="submit" name="submit" value="http://stackoverflow.com/questions/15755246/submit">Submit</button></form></body></html>\[/code\]
 
Back
Top