Forum Moderators: coopster

Message Too Old, No Replies

unexpected t string

error in <form method="post" action="<?php echo $PHP_SELF;?>">

         

sunnydayzrback

11:32 am on May 16, 2007 (gmt 0)

10+ Year Member



Hi,
When I try to run the following code, I get the following error message.

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>

Scally_Ally

11:40 am on May 16, 2007 (gmt 0)

10+ Year Member



This error usually means that there is a syntax error in your script.

Check line 38, and the line before, for any anomilies (think thats how you spell it).

This looks like the culprit.


echo("$msg);

Ally

sunnydayzrback

12:04 pm on May 16, 2007 (gmt 0)

10+ Year Member



Thank you very much.So silly of me to overlook that. By the way its spelt "anamolies".

jatar_k

12:28 pm on May 16, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



hehe

by the way it's actually spelled 'anomalies' but we aren't sticklers for spelling except in our code ;)

Welcome to WebmasterWorld