I'm new to php and i'm trying to code guess the number script without MySQL now my problem is the loop runs forever, the DEMO HERE and the php code looks like
PHP Code:
<?php
print '<html>
<head>
<title>KONVICT.mobi | online games | Guess the number</title>
<link rel=\'stylesheet\' href=\'./style.css\' type=\'text/css\'/>
</head>
<body><img src=\'./logo.png\' alt=\'GTN\'/><br>
This page should allow to play GTN game<br><br>
Enter your guess between zero and 30';
//Generate a random number between zero and 30
$num = rand(0,30);
//Accept and post input from user
$input = print '<form action=\'GTN.php\' method=\'POST\'>
<input type=\'text\' name=\'input\' size=\'2\'><br>
<input class=\'buttom\' type=\'submit\' value=\'Guess\'>
</form>';
$guess = $_POST["input"];
if($guess==$num)
print 'You are correct! the number is'.$num.'!';
//If input incorrect allow user to try again
while($num!=$guess)
{
if($guess<$num)
{
print 'Guess low try again :';
$input = print '<form action=\'GTN.php\' method=\'POST\'>
<input type=\'text\' name=\'input\' size=\'2\'><br>
<input class=\'buttom\' type=\'submit\' value=\'Guess\'>
</form>';
}
else
{
print 'Guess high, try again :';
$input = print '<form action=\'GTN.php\' method=\'POST\'>
<input type=\'text\' name=\'input\' size=\'2\'><br>
<input class=\'buttom\' type=\'submit\' value=\'Guess\'>
</form>';
}
}
print '</body>
</html>';
?>
Comment