2011-03-06 107 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*/ 
?>