473,480 Members | 1,774 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Parse error: syntax error unexpected T_IF

praclarush
27 New Member
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 10008
ronverdonk
4,258 Recognized Expert Specialist
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
praclarush
27 New Member
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 Recognized Expert Specialist
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
praclarush
27 New Member
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 Recognized Expert Specialist
Yes, maybe you inadvertently changed something. Your problem is solved anyway! See you again.

Ronald
Feb 22 '08 #6

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

Similar topics

8
46157
by: Wescotte | last post by:
The error message Parse error: syntax error, unexpected $end in FILE on line X is one I run into frequently and I know the cause is I missed an ending quote. Is there an easy way to determine...
36
7940
by: rhys | last post by:
My Gurus and Angels -- Please pardon this old-school programmer, only recently enlightened to open-source, having been trapped in the convenience of proprietary lingos for way too long. My...
3
6933
by: SilvaZodiac | last post by:
Hi everyone, I'm still rather new to PHP code, and I have a syntax error. I've tried several different solutions, but it won't fix. It seems to suggest that I need a new bracket somewhere in the...
2
3224
by: fburn | last post by:
I need some help with an error I'm getting using php 5.2.5 running on linux. I receive an error: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or...
9
3515
akohistani
by: akohistani | last post by:
I am having Parse error problem with my newly purchased Php upload script I have uploaded the script and I get the error below Parse error: syntax error, unexpected $end in URL/functions.php on...
3
5581
paulrajj
by: paulrajj | last post by:
hi to all, i am getting syntax error on my code.. Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in D:\xampp\htdocs\Dummy\paulraj\matrim\exam.php on line 62 ...
3
5164
by: brkseven | last post by:
Looking for help with this Contact Form. The error is on line 1, but that' doesn't mean a lot, I think. In fact, a php syntax check passed it, but I was hoping for an easy syntax error, it looks...
2
3086
by: Vicki Hendra | last post by:
Hi I am new to php fullstop I and colleagues have setup wordpress blogs for our local towns, giving the local businesses free advertisment. Part of the problem started when using wordpress...
3
2603
by: Ann Madden | last post by:
Hello - I am super green to php and mysql. I have received the following error: Parse error: syntax error, unexpected $end in C:\website\chart.php on line 84... I have been through the code matching...
0
7039
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7080
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5326
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4770
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
2992
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2977
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1296
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
558
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
176
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.