2011-03-06 70 views
0

每當我在我的PHP代碼中收到一個錯誤,我最終會得到一個新的錯誤。我沒有PHP那樣經驗豐富,所以這個網站對我非常有幫助。我不明白的PHP錯誤

我的代碼:

<?php 

/* This is the location of the file and will be */ 
/* used as the baseline for all of my files writing */ 
/* of code within php.*/ 

/* THIS REQUIRES THE FILES FOR THE APPLICATOIN */ 
require_once('websiteconfig.inc.php'); 

/*FUNCTION THE VALIDATE NAME ON FORM */ 
function validateLogin($emailaddress='', $password='') 
{ 

    /*THIS INIITALLIZES THE EMAIL KEY ON THE FORM */ 
    $email_key = '[email protected]'; 
    $password_key = '1234'; 
    $auth_match = 0; 

    /*THIS IS THE FIRST STATEMENT TO TEST THE USERNAME AND PASS*/ 
    if ($emailaddress == $email_key && $password == $password_key) 
    { 
    $auth_match=1; 
    } 

    /*THIS MAKES SURE THAT THE USER NAME AN PASSWORD IS MATCHED*/ 
    return $auth_match; 
} 

function sanitize($form_var) 
{ 
    $clean_data = strtolower(trim($form_var)); 

    return $clean_data; 
} 

/*AUTHENTICATION OF LOGON*/ 

$auth_status = 0; 

/*PULLED FROM THE LOGON ON FORM AND DETERMINES IF ON CLICK OCCURED*/ 
if(array_key_exists('submit', $_POST)) 
{ 
/*REMOVES OLD DATA ON LOGON*/ 
    $emailaddress = sanitize($_POST['emailaddress']); 
    $password = sanitize($_POST['password']); 

    /*This makes sure that each fiedl was processed correctly*/ 

    try 
    { 
    if($emailaddress == '' || $password == '') 
    { 
     throw new Exception ('E-mail and password must be provided to log in to this site. Please try again.'); 
    } 
    else 
    { 
     /* Validate data */ 
     $auth_status =validateLogin($emailaddress , $password); 

     /*this kicks of the exception*/ 
     try 
     { 
      if(!isset($auth_status)) 
      { 
     throw new Exception('Sorry, online banking is not available at this time. Please try again.'); 

      } 
     } 
     /*Check validation of password*/ 

     catch(exception $v) { 

     echo 'Message: ' . $v->getMessage(); 
     exit(); 
    } 

    /*try catch for failed authentication*/ 

    try 
    { 
     if($auth_status <= 0) 
     { 
     /*through trigger */ 
     throw new Exception('Sorry, the email address and password does not match our records. Please try again!'); 

     } 
     else 
     { 
      /*This creates the person object*/ 
      $currentMember = new Person($auth_status); 

      /*set the currentMember atributes*/ 
      $currentMember->firstname = 'Jenny'; 
      $currentMember->lastname = 'Ginny'; 
      $currentMember->emailaddress = '[email protected]'; 
      $currentMember->memberid = $auth_status; 

      /*start session*/ 
      session_start(); 
      $_SESSION['currentMember'] = serialize($currentMember); 
     } 
    } 
    catch(Exception $a) { 
    echo '<h3>Error: ' . $a->getMessage() .'</h3>'; 
} 


/*check validaiton of login */ 
catch(Exception $e) 
{ 
    echo 'Message: ' . $e->getMessage(); 
    exit(); 
} 

if($auth_status == 1) 
{ 
    /*THE LOGON IS SUCCESSFUL*/ 
    echo '<table width="400" border="1" align="center"><tr> <td><h3>Welcome Back, Betty!... Your not ugly after all</h3></td></tr> </table>' . "\n\n"; 
    echo "\t" . '<table width="400" border="1" align="center"><tr> <td><li><a href="' .  URL_ROOT . 'onlinebanking" title="Online Banking">On Line Banking</a></li></td></tr> </table>' . "\n\n"; 

} 
elseif($auth_status == 0) 
{ 
    /*THIS OCCURS IF THE LOGON FAILS*/ 
    echo '<table width="400" border="1" align="center"> <tr> <td> <h4  class="error">Authentication Error please try again! </h4></td></tr> </table>' . "\n\n"; 
echo '<table width="400" border="1" align="center"><tr> <td><p> Please make sure that the <strong> "Numbers Lock" </strong>or "<strong>Caps Lock"</strong> is not on and re-type your password.</p>&nbsp;</td> </tr> </table>'; 
} 

?> 
+3

你沒告訴我們的錯誤!您發佈了很多代碼,但沒有錯誤消息。請發佈您在瀏覽器中獲得的錯誤消息! – markus 2011-03-06 19:39:38

+2

這個php文件中有太多東西。閱讀「分離問題」和MVC模式。作爲第一步,嘗試將html標記與業務邏輯(例如,身份驗證)分開。 – markus 2011-03-06 19:41:58

+1

也認爲代碼,所以它更清晰 – cMinor 2011-03-06 19:41:58

回答

1

如果您沒有收到任何錯誤,就把下面幾行:

<?php 
error_reporting(E_ALL); 
ini_set('display_errors', 1); 
/*YOUR CODE*/ 
?>