• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 232
  • Last Modified:

I Get a Syntax Error: Expected:

I am using netbeans IDE and have some php
I include a file, create an object based on the include file session.class
I test a session variable, curly bracket
place a comment close the curly bracket and this second curly bracket is highlighted and I get a syntax error expected a whole list of items that could be right
I do not understand why this is happening

Can anybody please explain why this happens

attached is the code I have the problem with

and a screen print of netbeans

 netbeanserror.docx
<?php
require_once("./include/Session.class");
$sess = new Session();
$test = $sess->getVariable("auth");
if ( $test == "yes" );
{
    // seesion authorised = yes
}
else
{
    file_put_contents("filename.txt",$sess->getVariable('auth'), FILE_APPEND);
    header("Location: index.php");
    exit();
}
/*
 *  Program:  UMCSITE1.php
  * Desc:     Create user managed codes that manage dropdown lists
  *
  *
  */
require_once("./include/WebForm.class");
require_once("./include/Account.class");
require_once("./include/Database.class");
require_once("./include/Email.class");
require_once("./include/umcs.class");


try
{
  $form =
    new WebForm("umcsform.inc","umcsflds.inc",$_POST);
}
catch(Exception $e)
{
  echo $e->getMessage();
  exit();
}
//First time form is displayed. Form is blank. //
if (!isset($_POST['Button']))
{
   $form->displayForm();
   exit();
}
// Process form that has been submitted with user info  //
else
{
  try
  {
     $db = new Database("./include/Vars.inc");
     $db->useDatabase("r3prototype");
     $acct = new Account($db->getConnection(),"umcs");
  }
  catch(Exception $e)
  {
     echo $e->getMessage()."\n<br>";
     exit();
  }

  // Save and add in form was submitted  //
  if ($_POST['Button'] == "Save")
  {
     $not_required[] = "euser_cr_NID";
     $not_required[] = "euser_am_NID";
     $not_required[] = "amend_date";
     $not_required[] = "create_date";
     try
     {
         $form->setFieldsNotRequired($not_required);
         $blanks = $form->checkForBlanks();
     }
     catch(Exception $e)
     {
         echo $e->getMessage();
     }
     if(is_array($blanks))
     {
        $GLOBALS['message_2'] =
           "The following required fields were blank.
                Please enter the required information:  ";
        foreach($blanks as $value)
        {
           $GLOBALS['message_2'] .="$value, ";
        }
        $form->displayform();
        exit();
     }
     $form->trimData();
     $form->stripTagsFromData();
     try
     {
        $errors = $form->verifyData();
     }
     catch(Exception $e)
     {
        echo $e->getMessage();
     }
     if(is_array($errors))
     {
        $GLOBALS['message_2'] = "";
        foreach($errors as $value)
        {
           $GLOBALS['message_2'] .="$value<br> ";
        }
        $form->displayform();
        exit();
     }
     $newdata = $form->getAllFields();
     $newumcs = new umcs("./include/vars.inc");
     try
     {
      
       if(!$newumcs->createNewUmc($newdata, $sess->getVariable(user_name_logged)))
       {
         echo "Couldn't create new account.
                          Try again later.";
         exit();
       }

       }
     catch(Exception $e)
     {
       echo $e->getMessage();
       exit();
     }
     exit();
  }
  elseif($_POST['Button'] == "Cancel")
  {
     header("Location: index.php");
     exit();
  }
}

?>

Open in new window

0
johnecollins
Asked:
johnecollins
  • 5
  • 2
1 Solution
 
speak2abCommented:
I run into this error whenever i have put a method inside another method by mistake. Check the order and number of all the braces { }

Secondly, be sure you specify the error you catch with the Try. See: http://java.syntaxerrors.info/index.php?title=Syntax_error_on_token_%22catch%22,_finally_expected

This should get you started, If you have not resolved it by the time i am back I will look closely through your codes.

Goodluck.
0
 
johnecollinsAuthor Commented:
speak2ab:

  cheers thanks for that I will look at those points and will and deliberate

thanks for your swift reply

john
0
 
Ray PaseurCommented:
Line 5:

if ( $test == "yes" );

Remove the semicolon.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
johnecollinsAuthor Commented:
Ray,

Once again you have sorted me out, please can you tell me where you bought your glasses - I must get a pair ;-) I have been looking at this all night I was pulling out so much hair I was in danger of becoming your avatar ;-)

I really must come  to the US and buy you a beer!

semi-colon deleted and everything is marvelous
0
 
johnecollinsAuthor Commented:
Cheers Ray

Thank you so much

John
0
 
johnecollinsAuthor Commented:
speak2ab:

thank you for your effort as well
0
 
Ray PaseurCommented:
Ha!  You cannot imagine how many times I have reflexively typed a semicolon at the end of a foreach() or a where().  When you've been making the same mistake for years it becomes really easy to identify it ;-)

Thanks for the points (and maybe one day we can get that beer), ~Ray
0
 
johnecollinsAuthor Commented:
Hi  Ray, I am looking forward to it ;-)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now