Forum Moderators: coopster
Parse error: parse error, unexpected T_STRING in C:\wamp\www\tpbad\guess.php on line 38
This code to let the user guess a random number generated between one and 20.
Thanks.
<?php header("Cache-Control:no-cache");
function sun()
{
global $num;
srand((double)microtime() * 1000000);
$num=rand(1,20);
}
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Guess</title></head>
<body>
<?php
if($num==null)
{
$msg="Guess a no b/w 1 and 20";
}
if($num!= null &&!is_numeric($guess))
{
$msg="Invalid Guess";
}
else if($guess==$num)
{
if ($num!= null)
{
$msg="Correct guess , number is $num";
$msg.="<a href=\"$PHP_SELF\">";
$msg.="Try again?</a>";
}
sun();
}
else if($guess>$num)
{echo("Lower than this");}
else if($guess<$num)
{echo("Higher than this");}
echo("$msg);
?>
<form method="post" action="<?php echo $PHP_SELF;?>">
<input type ="hidden" name="no" <?php $num=$_POST["no"];?> value = "<?php echo($num);?>">
Guess:<input type="text" name="guess">
<input type="submit" value="Submit"><?php $guess=$_POST["guess"];?>
</form>
</body>
</html>