2011-02-05 14 views
0

私がログオンしようとすると、認証されていません - 私はエラーを返していません。ユーザー名とパスワードはコードにあります(ユーザー名とパスワードはデータベースに保存されていないPHPコードの中にあります)。基本的な質問PHPで

elseif($auth_status == 0); { 
echo '<h4>Authentication error please try again! </h4>' . "\n\n"; 

が不十分フォーマットされている(そしておそらくあなたが望んでいないものを)

<?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. */ 

/*require files for application */ 
require_once('websiteconfig.inc.php'); 


define('ABSOLUTE_PATH ', '../public_html/cit0215/assignment2/'); 


/*This will define my index.php file */ 
define('URL_ROOT ', 'https://wiki.cit.iupui.edu/~mjcrawle/cit0215/assignment2/index.php/'); 



/*functions that validate logins */ 


function validateLogin($emailaddress='', $password='') { 
/*Initialized the Variable from the original from the form */ 
    $email_key = '[email protected]'; 
    $password_key = '1234'; 
    $auth_match = 0; 

    /*This is the first If statement the test username and password*/ 
    if ($emailaddress == $email_key && $password == $password_key) { 
     $auth_match=1; 
    } 


    /*this is what ensure the username and password are correct*/ 
    return $auth_match; 
} 


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


/*Authticate the status of logins*/ 
$auth_status =0; 

/*Determine if the form data was submitted*/ 
if (array_key_exists('submit', $_POST)){ 
    /*this removes left over data*/ 
    $emailaddress = sanitize($_POST['emailaddress']); 
    $password = sanitize($_POST['password']); 

    /*verify form data*/ 
    $auth_status = validateLogin($emailaddress, $password); 
} 


include('header/header.inc.php');{ 
    if($auth_status == 1){ 
     /*successful logon*/ 

     echo '<h3>Welcome Back, Betty!... Your not ugly after all</h3>' . "\n\n"; 
    echo '<ul>' . "\n"; 
    echo "\t" . '<li><a href"' . URL_ROOT . 'onlinebanking" title="Online 

Banking">On Line Banking</a> </li>' . "\n\n"; 
    echo '</u>'; 
    } 


    elseif($auth_status == 0); { 
     /*authentication has failed*/ 
    echo '<h4>Authentication error please try again! </h4>' . "\n\n"; 
    echo '<p> Please make sure that the "Numbers lock" or "Caps Lock" is not 

on and re-type your password.</p>'; 
    } 


    include('footer_nav/footer.inc.php'); 
} 
?> 
+1

あまりにも多くの改行、あまりにもインデントされた行。コードを適切にフォーマットしてください。私は疑問に答えるために膨大な量の空白をスクロールする必要はありません。 – ThiefMaster

+0

どのようにログオンしようとしていますか?このコードに提出するフォームはどこですか? submitという名前の要素がありますか?このコードを実行すると、$ _POSTには何が入っていますか? –

+1

申し訳ありませんが、これは最初に基本的なデバッグを必要とします。テスト出力を1行ごとに作成して、正確な問題を特定して、それほど違和感のないようにしてください。 *それは質問の価値がある。 –

答えて

1

お知らせ:

は、これは私のコードです。何がするのは、$auth_statusがゼロの場合に;(no-op、つまり何もしない)を実行することです。

if ($auth_status) { 
    echo '<h3>Welcome Back, Betty!</h3>'; 
} else { // or elseif (!$auth_status) { // <-- no semi-colon 
    echo '<h4>Authentication error please try again! </h4>' . "\n\n"; 
} 
+0

ありがとう...私のフォームにも問題がありました。私のフォーム名は "Email"と "emailaddress"でしたあなたが提供したものは、最初の呼び出しエラーを修正した後に私が得たエラーを解決しました。 –

+0

私はPHPにはとても新しい –

1

コードに論理エラーがあります。

<?php 
    /* This is the locaiton of the file and will be */ 
    /*used as the baseline for all of my files writing */ 
    /*of code within php. */ 
    /*require files for application */ 

    require_once('websiteconfig.inc.php'); 

    define('ABSOLUTE_PATH ', '../public_html/cit0215/assignment2/'); 

    /*This will define my index.php file */ 
    define('URL_ROOT ', 'https://wiki.cit.iupui.edu/~mjcrawle/cit0215/assignment2/index.php/'); 

    /*functions that validate logins */ 
    function validateLogin($emailaddress='', $password='') { 
     /*Initialized the Variable from the original from the form */ 
     $email_key = '[email protected]'; 
     $password_key = '1234'; 
     $auth_match =0; 
     /*This is the first If statement the test username and password*/ 
     if($emailaddress == $email_key && $password == $password_key) { 
      $auth_match=1; 
     } 

     /*this is what ensure the username and password are correct*/ 
     return $auth_match; 
    } 

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

    /*Authticate the status of logins*/ 
    $auth_status =0; 

    /*Determine if the form data was submitted*/ 
    if (array_key_exists('submit', $_POST)){ 
     /*this removes left over data*/ 
     $emailaddress = sanitize($_POST['emailaddress']); 
     $password = sanitize($_POST['password']); 
     /*verify form data*/ 
     $auth_status = validateLogin($emailaddress, $password); 
    } 

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

     if($auth_status == 1){ 
      /*successful logon*/ 
      echo '<h3>Welcome Back, Betty!... Your not ugly after all</h3>' . "\n\n"; 
      echo '<ul>' . "\n"; 
      echo "\t" . '<li><a href"' . URL_ROOT . 'onlinebanking" title="Online Banking">On Line Banking</a> </li>' . "\n\n"; 
      echo '</u>'; 



// FIXME - ";" do not operation here. Your test for $auth_status do nothing. 
     } elseif($auth_status == 0); { 
      /*authentication has failed*/ 
      echo '<h4>Authentication error please try again! </h4>' . "\n\n"; 
      echo '<p> Please make sure that the "Numbers lock" or "Caps Lock" is not on and re-type your password.</p>'; 
     } 

     include('footer_nav/footer.inc.php'); 

    ?> 

ブレークラインエラーが多く発生しています。

0

奇妙な括弧がありましたが、これをテストできますか?

<?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. */ 
    /*require files for application */ 
    require_once('websiteconfig.inc.php'); 
    define('ABSOLUTE_PATH ', '../public_html/cit0215/assignment2/'); 
    /*This will define my index.php file */ 
    define('URL_ROOT ', 'https://wiki.cit.iupui.edu/~mjcrawle/cit0215/assignment2/index.php/'); 
    /*functions that validate logins */ 
    function validateLogin($emailaddress='', $password='') { 
     /*Initialized the Variable from the original from the form */ 
     $email_key = '[email protected]'; 
     $password_key = '1234'; 
     $auth_match = 0; 
     /*This is the first If statement the test username and password*/ 
     if ($emailaddress == $email_key && $password == $password_key) { 
      /*this is what ensure the username and password are correct*/ 
      return 1; 
     } 
     return false; 
    } 
    function sanitize($form_var){ 
     $clean_data = strtolower(trim($form_var)); 
     return $clean_data; 
    } 
    /*Authticate the status of logins*/ 
    $auth_status =0; 
    /*Determine if the form data was submitted*/ 
    if (array_key_exists('submit', $_POST)){ 
     /*this removes left over data*/ 
     $emailaddress = sanitize($_POST['emailaddress']); 
     $password = sanitize($_POST['password']); 
     /*verify form data*/ 
     if (validateLogin($emailaddress, $password)){ 
      $auth_status = 1; 
     } 
    } 
    include('header/header.inc.php'); 
    if($auth_status == 1){ 
     /*successful logon*/ 
     echo '<h3>Welcome Back, Betty!... Your not ugly after all</h3>' . "\n\n"; 
     echo '<ul>' . "\n"; 
     echo "\t" . '<li><a href"' . URL_ROOT . 'onlinebanking" title="Online Banking">On Line Banking</a> </li>' . "\n\n"; 
     echo '</u>'; 
    } 
    else{ 
     /*authentication has failed*/ 
     echo '<h4>Authentication error please try again! </h4>' . "\n\n"; 
     echo '<p> Please make sure that the "Numbers lock" or "Caps Lock" is not on and re-type your password.</p>'; 
    } 
    include('footer_nav/footer.inc.php'); 
    ?>