Guess the number script error

Started on the old forum in October 2010 · view the original in the archive · old links redirect here

#coding #error #games #php #script

2 replies · 437 views · started 16 years ago · 1 min read

2 participants
s3nzo Developer · 156 posts #1

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
	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>';
	
	
	
	
?>
s3nzo Developer · 156 posts #3

Thank you bro, i am getting another error but i will try to fix it, if i can't i will post here again but the loop problem is solved

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close