Posted by Mike on 07/18/06 14:42
try this version...
<?php
$num_to_guess = 42;
$num_tries = (isset($_POST[num_tries])) ? $_POST[num_tries] + 1 : 1;
if (!isset($_POST[guess])) {
$_POST[guess] = "0";
$message = "Welcome to the guessing game";
} else if ($_POST[guess] > $num_to_guess) {
$message = "* $_POST[guess] is too big! Try a smaller number.";
} else if ($_POST[guess] < $num_to_guess) {
$message = "* $_POST[guess] is too small! Try a bigger number.";
} else {
$message = "Well Done!";
}
?>
<html>
<head>
<title>Guessing Game</title>
</head>
<body>
<h1><?php echo $message ?></h1>
<p><strong>Guess Number:</strong> <?php echo $num_tries; ?></p>
<form action="<?php echo $_SERVER[PHP_SELF]; ?>" method="POST">
<p><strong>Type your guess here:</strong>
<input type="text" name="guess" value="<?php echo $_POST[guess]; ?>">
<font color="#FF0000"><?php echo $message ?> </font>
<input type="hidden" name="num_tries" value="<?php echo $num_tries;
?>">
<p><input type="submit" value="submit your guess"></p>
</form>
</body>
</html>
Mike
Navigation:
[Reply to this message]
|