468,514 Members | 1,075 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,514 developers. It's quick & easy.

Parse error: syntax error unexpected T_IF

praclarush
I've just started php, and this is a class assignment, but my question is Iím getting this error PHP Parse error: syntax error, unexpected T_IF, expecting T_VARIABLE or '$' in C:\wamp\www\ssp\SSP04\guessingGame.php on line 42. Iíve tried to make sense of it but Iím at a lose, there error is referring to this segment of the code.


[PHP]else{
if(!isset($_GET['word'])){
echo "<p>****</p>";
$guess = "****";
}//end if
//declaring some vaiables.
$guessedWord = $_GET['word'];
$guess = $_GET['letter']; //this is line 42
$secretArray = str_split($secretWord, 1);
$guessedArray = str_split($guessedWord, 1);


[/PHP]
this code is being called by a form
what I don't understand is that all of the if statements have been closed and there isn't a if statement on that line, though i know that sometime the error could be a few lines up...If anyone could please point me in the right direction it would be a great help

Thanks Praclarush
Feb 22 '08 #1
5 9600
ronverdonk
4,258 Expert 4TB
All I can see from the code shown is that the else branch in line 1 is not closed. But I assume that is not the error. With an error like this the reason is usually somewhere far before the error line shown.

So show all code for this script and we'll have a look.

Ronald
Feb 22 '08 #2
Thanks for the replay heres all the code I have

[PHP]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!-- meta tag info -->
<meta name="author" content="" />
<meta name="Apollo1 Account" content="" />
<meta name="revised" content="2/22/08" />
<meta name="filename" content="guessingGame.php" />
<meta name="description" content="Try to guess a hidden word" />
<meta name="keywords" content="word guessing game" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Content-Language" content="en-us" />
<title>Guessing Game</title>
</head>
<body>
<!--begain html code.-->
<div id="title" class="heading">
<h1>Guessing Game</h1>
</div>
<div id="directions" class="heading">
<h4>Try to guess the hidden word by entering a letter and clicking submit letter</h4><hr />
</div>
<!--end html code begain php code.-->
<?php

//hidden word.
$secretWord = "test";
//check to see if word is finished.
$finished = false;
//check if user entered a letter.
if(!isset($_GET['letter']))
{echo "<p>Please enter a letter</p>";}
else if(is_numeric($_GET['letter']))
{echo "<p>Please enter a letter, you entered a number</p>";}
else{
if(!isset($_GET['word'])){
echo "<p>****</p>";
$guess = "****";
}//end if
//declaring some vaiables.
$guessedWord = $_GET['word'];
$guess = $_GET['letter'];
$secretArray = str_split($secretWord, 1);
$guessedArray = str_split($guessedWord, 1);
$count = 0;
$arraySize = count($secretArray);

//checking to see if letter is in secret word.
while($count <= $arraySize) {
if($secretArray[$count] == $guess) {
$guessedArray[$count] = $guess;
}//end if.
$count++;
}//end while loop.
$guessedWord = implode($guessedArray);
if(strpos($guessedWord, '*') !== false) {
echo "<p>you've guessed correctly! The secret word is: ", $guessedWord, "</p>";
} else {
echo "<p>Secret Word: ", $guessedWord, "</p>";
}//end checking if word is finished

}//end check if
?>
<!--end php code begain html code.-->
<div id="guess" class="guess">
<form id="guessing" action="SSP04/guessingGame.php" method="get" enctype="application/x-www-form-urlencoded">
<p>
<input type="text" name="letter" size="5" maxlength="1" value="<?php if(!empty($_GET['letter'])) echo $_GET['letter']; ?>" />
</p>
<p>
<input type="hidden" name="word" size="20" value="<?php echo $guessedWord; ?>" />
</p>
<p>
<input type="submit" value="submit letter" />
</p>
</form>
</div>

</body>
</html>
[/PHP]

thanks
Praclarush
Feb 22 '08 #3
ronverdonk
4,258 Expert 4TB
I am running that code and get no error whatsoever! Are you sure this is the code with the error?

Ronald
Feb 22 '08 #4
I am running that code and get no error whatsoever! Are you sure this is the code with the error?

Ronald
yes I am sure its this code, but the thing is I just retried to as well just after you post and yet it worked, I don't understand it... strange I hate it when code does this, I may have done something when I was copying it any way Im sorry for wasting your time,

Praclarush
Feb 22 '08 #5
ronverdonk
4,258 Expert 4TB
Yes, maybe you inadvertently changed something. Your problem is solved anyway! See you again.

Ronald
Feb 22 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

By using this site, you agree to our Privacy Policy and Terms of Use.