2012-03-25 174 views
1

我爲使用PHP的網站創建登錄名,但是當我嘗試登錄時,我總是得到相同的錯誤「您忘記輸入密碼了。」如果用戶忘記輸入密碼,則包括一個錯誤,但是我一直在輸入密碼。任何幫助將不勝感激。PHP密碼驗證錯誤

的PHP:

//check for a password and a match against the confirmed password: 
if (empty($_POST['pass1'])) 
{ 
    if($_POST['pass1'] != $_POST['pass2']) 
    { 
     $errors[] = 'Your passwords did not match.'; 
    } 
    else 
    { 
     $p = trim($_POST['pass1']); 
    } 
} 
else 
{ 
    $errors[] = 'Your forgot to enter your password.'; 
} 

if (empty($errors)) //if everything is okay 
{ 
//register the user in the database 
require_once 
('../mysqli_connect.php'); //connect to the DB 

HTML表單:

 <p>Password: <input type="password" name="pass1" size="15" maxlength="20"/>*</p> 

    <p>Confirm Password: <input type="password" name="pass2" size="15" maxlength="20"/>*</p> 

預先感謝!

+0

它應該是'如果(!空($ _ POST [ 'PASS1']))' 。 – JJJ 2012-03-25 13:27:31

回答

2

如果密碼不爲空(else爲空),您的代碼表示發送錯誤消息。或者切換thenelse左右的塊,或在empty之前放置!

+0

非常感謝,這總是一件小事,我一直在圈子裏一個小時,多麼令人沮喪。 – PurpleSmurph 2012-03-25 13:30:43

+0

總是這樣。看起來你在檢查錯誤的時候會把「如果空」當成「一切正常」的情況下讓你感到困惑,並將相同的推理應用到「有密碼」的情況下。 – 2012-03-25 13:32:52

+0

現在繼續調試其餘部分。感謝您的幫助。 – PurpleSmurph 2012-03-25 13:35:25

0
if (!empty($_POST['pass1'])) 
{ 
    if($_POST['pass1'] != $_POST['pass2']) 
    { 
     $errors[] = 'Your passwords did not match.'; 
    } 
    else 
    { 
     $p = trim($_POST['pass1']); 
    } 
} 
else 
{ 
    $errors[] = 'Your forgot to enter your password.'; 
} 
0
//check for a password and a match against the confirmed password: 
if (!empty($_POST['pass1'])) 
{ 
    if($_POST['pass1'] != $_POST['pass2']) 
    { 
     $errors[] = 'Your passwords did not match.'; 
    } 
    else 
    { 
     $p = trim($_POST['pass1']); 
    } 
} 
else 
{ 
    $errors[] = 'Your forgot to enter your password.'; 
} 
.... 
0

您的邏輯是錯誤的。 你的代碼表明, 「如果你PASS1是EMPTY,比較pass1pass2」 正確的代碼

if (!empty($_POST['pass1'])) 
{....} 
else{....}