Parse error: syntax error unexpected T_IF

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • praclarush
    New Member
    • Oct 2007
    • 27

    Parse error: syntax error unexpected T_IF

    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\guessing Game.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($secr etWord, 1);
    $guessedArray = str_split($gues sedWord, 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
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    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

    Comment

    • praclarush
      New Member
      • Oct 2007
      • 27

      #3
      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="guessi ngGame.php" />
      <meta name="descripti on" 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>Guessi ng 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($secr etWord, 1);
      $guessedArray = str_split($gues sedWord, 1);
      $count = 0;
      $arraySize = count($secretAr ray);

      //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($guesse dArray);
      if(strpos($gues sedWord, '*') !== 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.ph p" method="get" enctype="applic ation/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

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

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

        Ronald

        Comment

        • praclarush
          New Member
          • Oct 2007
          • 27

          #5
          Originally posted by ronverdonk
          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

          Comment

          • ronverdonk
            Recognized Expert Specialist
            • Jul 2006
            • 4259

            #6
            Yes, maybe you inadvertently changed something. Your problem is solved anyway! See you again.

            Ronald

            Comment

            Working...