2014-05-05 83 views
-2

我的問題是我想創建一個登錄屏幕,註冊表單和丟失的密碼錶單。我設法在登錄屏幕上創建了一條錯誤消息,但是在註冊表單中執行時卻沒有這樣做。 所以我的問題是,我怎樣才能將我的註冊表單參數添加到函數auth中,它將爲註冊表單執行相同操作?php登錄的一些問題

case "authent": 
auth(); 
break; 

function auth(){ 
    global $myurl; 
    $errors=array(); 
    $username=""; 
    $passwd=""; 
    if (isset($_POST['username']) && $_POST['username']!="") { 
     $username=$_POST['username']; 
    } else { 
     $errors[]="Username missing!"; 
    } 
    if (isset($_POST['passwd']) && $_POST['passwd']!="") { 
     $passwd=$_POST['passwd']; 
    } else { 
     $errors[]="Password missing, fill the blank!"; 
    } 

    if (empty($errors)){ 
     // no errors, check the information 
     if ($username=="user" && $passwd=="password"){ 
      // correct information 
      header("Location: $myurl?mode=success"); 
     } else { 
      // wrong information, back to login.html 
      $errors[]="Vale info, proovi uuesti."; 
      include("view/login.html"); 
     } 
    } else { 
     // errors with messages 
     include("view/login.html"); 
    } 
} 
+0

你爲什麼要包括的login.php頁面?如果有任何錯誤,那麼你在同一頁面上。只顯示錯誤(s)。 – user3470953

+0

感謝您指出,我的計劃是爲錯誤彈出一個錯誤,這只是一個暫時的事情。你有什麼想法如何讓函數適用於多種情況? – user3225423

回答

0

試試這個...

if(isset($_POST['submit'])){ 
    $username = $_POST['username']; 
    $passwd = $_POST['passwd']; 
    if($username == ''){ 
     $errrors[] = "Username missing!"; 
    }elseif($passwd == ''){] 
     $errors[] = 'Password missing!'; 
    } 
} 

,而不是這個......

if (isset($_POST['username']) && $_POST['username']!="") { 
    $username=$_POST['username']; 
} else { 
    $errors[]="Username missing!"; 
} 
if (isset($_POST['passwd']) && $_POST['passwd']!="") { 
    $passwd=$_POST['passwd']; 
} else { 
    $errors[]="Password missing, fill the blank!"; 
} 
+0

它沒有工作對我來說也許我做錯了什麼......我會後的完整代碼:http://pastebin.com/nBVxVCVG – user3225423

+0

我的目標是讓其他網頁發佈錯誤消息太喜歡登錄。 HTML頁面,但我無法獲得該功能...對不起,我的英文不好! – user3225423