You are here: Re: Self calling form not working. « All PHP « IT news, forums, messages
Re: Self calling form not working.

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация