2012-03-10 70 views
-4

我缺少一个无法找到的大括号。 解析错误显示在我的代码的末尾。我已经在此永远度过。我不太擅长PHP提示如何识别这些错误会有所帮助。在我的PHP代码中缺少大括号

<?php 

       /*Required Fields*/ 
       require_once('websiteconfig.inc.php'); 
       include (ABSOLUTE_PATH . 'class/person.class.php'); 

       /*Starts the session for the person class*/ 
       session_start(); 


       /*FUNCTIONS*/ 

       /*VERRIFY EMAIL ADDRESS AND PASSWORD AND MATCH IN SYSTEM*/ 
       function validateLogin($emailaddress='', $password=''){ 

       /*INITIALIZES VARIABLES*/ 
       $email_key = '[email protected]'; 
       $password_key = '1234'; 

       $auth_match = 0; 

       /* CHECK FOR MATCH */ 
       if($emailaddress == $email_key && $password == $password_key){ 
        $auth_match = 1; 
        } 
       return $auth_match; 
       } 

       /*CLEAN FORM DATA*/ 
       function sanitize($form_var) { 
        $clean_data = strtolower(trim($form_var)); 

        return $clean_data; 
       } 

       /*PAGE VARIABLES*/ 
       $auth_status = 0; 

       /*DETERMINE FORM HAS BEEN SUBMITTED*/ 
       if(array_key_exists('submit', $_POST)) { 

       /*SANITIZE FORM DATA*/ 
       $emailaddress = sanitize($_POST['emailaddress']); 
       $password = sanitize($_POST['password']); 

       /*VALIDATE FORM DATA*/ 
       $auth_status = validateLogin($emailaddress, $password); 

       } 


       /*CONFIRM EACH FIELD WAS PROCESSED*/ 
       //trigger login field exception 
       try{ 
        if($emailaddress == '' || $password == ''){ 
         throw new Exception('E-mail and password must be supplied to login. Please try again.'); 
        }else{ 
         /*VALIDATE FOR DATA*/ 
         $auth_status = validateLogin($emailaddress, $password); 

         //trigger validation exception 


         try{ 
          if(!isset($auth_status)) { 
           throw new Exception('Online Banking is not available at this time. Please try again later.'); 
          } 
         } 



         // catch validation exception 
         catch(Exception $v) { 
          echo 'message: ' . $v->getMessage(); 
          exit(); 
         } //end catch 

         //This triggers the validation of authentication 
         try{ 
          if ($auth_status == 0){ 
          throw new Exception('Email address and or Password does not meet our records! Please try again.'); 
          }elseif ($auth_status>0){ 
           /*Member Session*/ 
           $currentMember = new Person($auth_status); 

           /*Set Attributes*/ 
           $currentMember->memberid = $auth_status; 
           $currentMember->firstname = 'Michael'; 
           $currentMember->lastname = 'Crawley'; 
           $currentMember->emailaddress = '[email protected]'; 

           /*Serialize currentMember object*/ 
           $_SESSION['currentMember'] = serialize($currentMember); 

        } 
       }// End try statment 

       //catch login field exception 
       catch(Exception $e) { 
        echo 'Message: ' . $e->getMessage(); 
        exit(); 
         }     

      ?> 





     </div><div class="container" id="shadow"> 
     <div> 
      <?php 

       include(ABSOLUTE_PATH . 'header.inc.php'); 

       if($auth_status == 1){ 
        /*AUTHENTICATION SUCCESS*/ 
        echo '<h4>Welcome Back, Betty!</4>' . "\n\n"; 
        echo '<ul>' . "\n"; 
        echo "\t" . '<li><a href="' . APP_ROOT . 'onlinebanking" title="Online Banking">Online Banking</a></li>' . "\n\n"; 
        echo '</ul>'; 


       } elseif($auth_status == 0){ 
        /*AUTHENTICATION FAILED*/ 
        echo '<h4 class="error">Authentication Error!</h4>' . "\n\n"; 
        echo '<p>Incorrect e-mail address and/or password submitted. Please try again.</p>'; 
       } 

      ?> 




       </div><!--End of main content--> 
      <?php 
       include(ABSOLUTE_PATH . 'footer.inc.php'); 
      ?> 

</div> 
+1

如果您使用像记事本+ + +编辑器,它会自动匹配和颜色编码你的括号。我就是这么做的...... – 2012-03-10 16:29:35

+0

你真的注意正确地缩进你的代码。在这里看到一些标准,选择一个并正确地遵循它。 http://en.wikipedia.org/wiki/Indent_style#K.26R_style – 2012-03-10 16:31:46

+0

你最后的其他如果。你写了elseif – 2012-03-10 16:32:54

回答

2

的常用方式以确保适当的托架匹配是缩进的内容的每个{}由比外部多一个选项卡。

0

您错过了在您的女巫代码中的第54行开启的'尝试'结构'catch'。

0

添加到您的代码

error_reporting(E_ALL); 

的顶部但是当你找不到错误,开始删除部分代码,并再次运行该文件的网页,直到错误消失。

例如,从您的代码中删除include footer.inc.php,删除一些PHP代码以实际找到导致错误的原因。然后,您可以慢慢添加代码以查看触发错误的原因。

0

通常情况下,这是不那么会是什么,但是......

if($emailaddress == '' || $password == ''){ 
    throw new Exception('E-mail and password must be supplied to login. Please try again.'); 
}else{ 
    /*VALIDATE FOR DATA*/ 

的“其他人”在这里似乎并不有一个匹配的右括号。至少,根据我的文本编辑器中的大括号匹配。 (值得期待......)

更新:实际上,您似乎缺少2个x闭合花括号。请参见下面的代码格式化: (见### THIS BRACE IS UNMATCHED ###标记。)

<?php 
/*Required Fields*/ 
require_once('websiteconfig.inc.php'); 
include(ABSOLUTE_PATH . 'class/person.class.php'); 

/*Starts the session for the person class*/ 
session_start(); 

/*FUNCTIONS*/ 

/*VERRIFY EMAIL ADDRESS AND PASSWORD AND MATCH IN SYSTEM*/ 
function validateLogin($emailaddress='', $password=''){ 

    /*INITIALIZES VARIABLES*/ 
    $email_key = '[email protected]'; 
    $password_key = '1234'; 

    $auth_match = 0; 

    /* CHECK FOR MATCH */ 
    if($emailaddress == $email_key && $password == $password_key){ 
    $auth_match = 1; 
    } 
    return $auth_match; 
} 

/*CLEAN FORM DATA*/ 
function sanitize($form_var) { 
    $clean_data = strtolower(trim($form_var)); 

    return $clean_data; 
} 

/*PAGE VARIABLES*/ 
$auth_status = 0; 

/*DETERMINE FORM HAS BEEN SUBMITTED*/ 
if(array_key_exists('submit', $_POST)) { 

    /*SANITIZE FORM DATA*/ 
    $emailaddress = sanitize($_POST['emailaddress']); 
    $password = sanitize($_POST['password']); 

    /*VALIDATE FORM DATA*/ 
    $auth_status = validateLogin($emailaddress, $password); 

} 


/*CONFIRM EACH FIELD WAS PROCESSED*/ 
//trigger login field exception 
try{ ### THIS BRACE IS UNMATCHED ### 
    if($emailaddress == '' || $password == ''){ 
    throw new Exception('E-mail and password must be supplied to login. Please try again.'); 
    }else{ ### THIS BRACE IS UNMATCHED ### 
    /*VALIDATE FOR DATA*/ 
    $auth_status = validateLogin($emailaddress, $password); 

    //trigger validation exception 


    try{ 
     if(!isset($auth_status)) { 
     throw new Exception('Online Banking is not available at this time. Please try again later.'); 
     } 
    } // closing `try` 



    // catch validation exception 
    catch(Exception $v) { 
     echo 'message: ' . $v->getMessage(); 
     exit(); 
    } //end catch 

    //This triggers the validation of authentication 
    try{ 
     if ($auth_status == 0){ 
     throw new Exception('Email address and or Password does not meet our records! Please try again.'); 
     }elseif ($auth_status>0){ 
     /*Member Session*/ 
     $currentMember = new Person($auth_status); 

     /*Set Attributes*/ 
     $currentMember->memberid = $auth_status; 
     $currentMember->firstname = 'Michael'; 
     $currentMember->lastname = 'Crawley'; 
     $currentMember->emailaddress = '[email protected]'; 

     /*Serialize currentMember object*/ 
     $_SESSION['currentMember'] = serialize($currentMember); 

     } 
    }// End try statment 

    //catch login field exception 
    catch(Exception $e) { 
     echo 'Message: ' . $e->getMessage(); 
     exit(); 
    }     

?> 





</div><div class="container" id="shadow"> 
<div> 
<?php 

    include(ABSOLUTE_PATH . 'header.inc.php'); 

    if($auth_status == 1){ 
     /*AUTHENTICATION SUCCESS*/ 
     echo '<h4>Welcome Back, Betty!</4>' . "\n\n"; 
     echo '<ul>' . "\n"; 
     echo "\t" . '<li><a href="' . APP_ROOT . 'onlinebanking" title="Online Banking">Online Banking</a></li>' . "\n\n"; 
     echo '</ul>'; 


    } elseif($auth_status == 0){ 
     /*AUTHENTICATION FAILED*/ 
     echo '<h4 class="error">Authentication Error!</h4>' . "\n\n"; 
     echo '<p>Incorrect e-mail address and/or password submitted. Please try again.</p>'; 
    } 

?> 




</div><!--End of main content--> 
<?php 
    include(ABSOLUTE_PATH . 'footer.inc.php'); 
?> 

</div> 
0

大多数编辑将能够突出对匹配的括号。

关于如何避免这些问题的提示:代码约定!我不会说在哪里准备什么,如果{和}应该在一个新的行或同一个位置,但总是以同样的方式进行。多年来,你会发现这些东西非常快 - 如果打算正确