2014-05-05 85 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