02-14-2012, 05:03 PM
|
#2 (permalink)
|
|
The Visitor
Join Date: Feb 2012
Posts: 2
Thanks: 0
|
Well, I've fixed it by using a hidden input and passing the value along via POST. Here's the working code:
Code:
<?php
if (!isset($_POST["guess"]))
{
$message = "What number am I thinking of?";
$num = rand(0,100);
}
else
{
$num = $_POST['num'];
if ($_POST["guess"] > $num)
{
$message = "Too high, guess again!";
}
else if ($_POST["guess"] < $num)
{
$message = "Too low, guess again!";
}
else
{
$message = "Correct!";
}
}
?>
<html>
<head><title>Number guess</title></head>
<body>
<?php echo $message ?>
<form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="POST">
<input type="text" name="guess"/>
<input type="hidden" name="num" value="<?php echo $num ?>" />
<p><input type="submit" value="Submit"/></p>
</form>
<?php echo $num ?>
</body>
</html>
|
|
|
|