The page displays a syntax error only in PHP 5.3.1, but a penalty at 5.2.6

I have two dev servers, one of which is the PHP version 5.3.1, which is located on my main development machine, and on a laptop that works as a simulated web server, there is PHP version 5.2.6.

An index page hosted with PHP 5.2.6 will display the page correctly. A page hosted on PHP version 5.3.1 does not work.

I get an error message:

Syntax error: syntax error, unexpected '}' in C: \ xampp \ htdocs \ Greek \ index.php on line 92

I have attached the code below. (However, I must warn you that it is quite large, and I can’t find a way to simply attach the file or something like that, so I’d better place the whole batch here. Sorry for that.)

I have googled around to see if something similar has happened before, but I cannot find anything. And I thought I would ask here.

But any help or guidance would be most appreciated.

<?php
 include_once( 'admin_dataHandler.php' );

// Lets have a handle on the data connection to the data base.
// The file must be edited so that it pointing to the correct data base.
 $dataHandler = new DataConnection();

 session_start();   // This connects to the existing session

 $msg = "";
 if ( $_SESSION['question_id'] ){
   $question_id = $_SESSION['question_id'];
 }else{
   $question_id = 1; /* Find first question */
 }
 // Debugging only...
 //echo $question_id;
 $answer = "";
 if ( $_REQUEST['action'] ){
   // an action was requested..
   $action = $_REQUEST['action'];
   if ( $action == "answer" ){
        if ( $_REQUEST['answer'] ){
            $answer = $_REQUEST['answer'];
            if ( $dataHandler->checkGreekWordAnswer( $question_id , $answer ) ){ 
              /* Check to see if the answer was correct? */
              $question_id = $dataHandler->getNextGreekWordQuestion( $question_id ); /* Find next question */
              $answer = "";
              $msg = "correct, moving on to next question.";
              // then navigate to the next word.
            }else{
              $msg = "Incorrect. For help hit the hint button";
            }
        }
    }else if ( $action == "next" ) {
        $qid = $question_id;
        $question_id = $dataHandler->getNextGreekWordQuestion( $question_id );
        if( $question_id == null ){
            $msg = "There are no more questions in this quiz";
            // Keep the user where they're at....
            $question_id = $qid;
        }
    }else if ( $action == "back" ){

        $question_id = $dataHandler->getPreviousGreekWordQuestion( $question_id );
        //echo "Current question id is " .$question_id;
        if( $question_id == null ){
            //echo "Something wrong here...";
            $msg = "You're at the beggining of the quiz.";
            $question_id = 1;
        }
    }else if ( $action == "hint" ){
        $msg = $dataHandler->getHint( $question_id );
        if( $msg == null ){
            $msg = "There are no hints for this question.  Sorry";
        }
    }
 } 
 $question = $dataHandler->getGreekWordQuestion( $question_id );
 $_SESSION['question_id'] = $question_id;

 /** Build the HTML page that going to be the front end of the quiz.*/
?><html>
  <head>
    <!-- CSS STUFF HERE....-->
    <link rel="stylesheet" type="text/css" href="layout.css">
    <script type="text/javascript" src="translator.js"></script>
    <title>Welcome to the Greek Quiz</title>
  </head>

  <body>
    <div id="header-block">
        <img>
        Welcome to the Biblical Greek Quiz
  </div>
<? if ( $question_id == -1 ) { ?>
<!-- this needs to be a java scripty pop up 
and this H1 section needs to be in red...-->
    <h1>You win!</h1> 
<? }else{ ?>
    <div id="quiz-section">
    <span class='question'><?php echo $question; ?></span>
    <form action='index.php' method='post'>
      <input type='text' size='20' name='answer' id='greekAnswer' onkeyup="trans(this.id)" value='<? echo $answer; ?>'></input>
      <button type='submit' name='action' value='answer'>Send</button>    
      <button type='submit' name='action' value='next'>Next</button>
      <button type='submit' name='action' value='back'>Back</button>
      <button type='submit' name='action' value='hint'>Get a hint.</button>     
    </form>
    </div>
<?php
} <--------------- THis is the } it not expecting....
?>
<?php
  if ( $msg != "" ){ ?>
<script language='javascript'>
   alert( "<?php echo $msg; ?>" );
</script>
    <?php
        }
    ?>
  </body>  
</html>

I pointed to the violation line at the end of my code.

+3
source share
3 answers

One server probably does not like your short open tags : <?. Try replacing them <?php.

+7
source

You mix tags <?phpand <?in your code. I believe that the <?default option is no longer recognized by PHP 5.3.

+6
source

PHP <? <?php. <? . <?php, .

+3

All Articles