2014-02-28 143 views
0

我對PHP很新穎,當單擊提交時我無法獲得此if語句。我的編輯器沒有顯示任何代碼錯誤,它似乎工作正常,除了它沒有迴應錯誤。註冊表格不顯示

<html> 
<LINK rel='stylesheet' href='style.css' type='text/css'> 

<?php 
$submit = $_POST['submit']; 
$username = strip_tags($_POST['username']); 
$password = strip_tags($_POST['password']); 
$repeatpassword = md5(strip_tags($_POST['repeatpassword'])); 

$date = date('Y-m-d'); 
echo $date; 
if ($sumbit) 
{ 
    if ($username&&$password&&$repeatpassword) 
    { 
     $password = md5($password); 
     $repeatpassword = md5($repeatpassword); 

     if ($password==$repeatpassword) 
     { 
      if(strlen($username)>25) 
      { 
       echo 'Length of username must be less than 25 charcters'; 
      } 
      else 
      { 
       if (strlen($password)>25||strlen($password)<6) 
       { 
        echo 'Your password must be 6 to 25 characters long'; 
       } 
       else 
       { 
        echo 'Success!'; 
       } 
      } 
     } 
     else 
     { 
      echo 'Passwords do not match'; 
     } 

    } 
    else 
     echo 'Fill in all the fields'; 
} 
?> 

<form action='register.php' method='POST'> 
    <table> 
     <tr> 
      <td>Username</td><br /> 
     </tr> 
     <tr> 
      <td><input type='text' name='username'></td><br /> 
     </tr> 
     <tr> 
      <td>Password</td><br /> 
     </tr> 
     <tr>  
      <td><input type='password' name='password'></td><br /> 
     </tr>  
     <tr>  
      <td>Repeat Password</td><br /> 
     </tr> 
     <tr> 
      <td><input type='password' name='repeatpassword'></td><br /> 
     </tr> 
    </table> 
     <p> 
      <input type='submit' name='submit' value='Register'> 
</form> 

</html> 
+0

提交什麼是你看到後?它展示了什麼? – SajithNair

+0

http://www.php.net/isset –

+0

sumbit應提交 – SajithNair

回答

0

試試這個

if(isset($_POST['submit'])) 
{ 
    if (isset($_POST['username'], $_POST['password'], $_POST['repeatpassword'])) 
    { 
    $username = strip_tags($_POST['username']); 

    $password = strip_tags($_POST['password']); 
    $repeatpassword = md5(strip_tags($_POST['repeatpassword'])); 

,而不是

if ($sumbit) 
{ 
    if ($username&&$password&&$repeatpassword) 
    { 
1

在你的代碼的開頭添加這樣的:

ini_set("display_errors", true); 
error_reporting(E_ALL); 

您必須啓用錯誤報告,它的轉身默認關閉afaik。無論如何:

if ($sumbit) 

我想你想檢查它的設置。在PHP該函數被調用isset(),因此您的代碼將是:

if(isset($submit)) {} 
+0

+1 for error_reporting(E_ALL); – SajithNair

3

有一個錯字

if ($sumbit) 

應該

if ($submit) 
+0

好眼睛。我沒有看到那一個。 –

+0

呵呵,因爲我每天都會做這些打字錯誤:D – SajithNair

+0

非常感謝。我認爲這將是一件愚蠢的事情。我正在使用與Java的工作,它會尖叫着你這樣的事情。 – Tom

0

你是使用sumbit並使用提交

if (!empty($submit)){ 


{ 
1

試試這個,它可能會幫助你。

if (isset($_POST['submit'])) 
{ 
    $submit = $_POST['submit']; 
    $username = strip_tags($_POST['username']); 

    $password = strip_tags($_POST['password']); 
    $repeatpassword = md5(strip_tags($_POST['repeatpassword'])); 

    $date = date('Y-m-d'); 
    echo $date; 
    if ((isset($username))&&(isset($password))&&(isset($repeatpassword))) 
    { 
     $password = md5($password); 
     $repeatpassword = md5($repeatpassword); 

     if ($password==$repeatpassword) 
     { 
      if(strlen($username)>25) 
      { 
       echo 'Length of username must be less than 25 charcters'; 
      } 
      else 
      { 
       if (strlen($password)>25||strlen($password)<6) 
       { 
        echo 'Your password must be 6 to 25 characters long'; 
       } 
       else 
       { 
        echo 'Success!'; 
       } 
      } 
     } 
     else 
     { 
      echo 'Passwords do not match'; 
     } 


    } 
    else 
     echo 'Fill in all the fields'; 

} 

和形式使用:

<form action='' method='POST'> 
    <input type='submit' name='submit' value='Register'> 
</form> 
0

存在的repeatpassword正在做兩次,密碼的MD5正在做一次MD5。所以,如果條件不滿足

if ($password==$repeatpassword) 

如果之前提交條件

$password = strip_tags($_POST['password']); 
$repeatpassword = md5(strip_tags($_POST['repeatpassword'])); 

裏面,如果提交條件

$password = md5($password); 
$repeatpassword = md5($repeatpassword);