2013-04-08 54 views
-2

嗨,我剛剛進入從數據庫中vaild用戶名和密碼的時候,但是當我輸入一個無效的用戶名和密碼,它只是循環使用PHP和MySQL的登錄系統的工作創建一個登錄系統回到即使我已經statment登錄頁面說它失敗,如果登錄這裏失敗,我想打印的是我的代碼文件PHP登錄系統不會響應錯誤陳述

<?php 
require_once("Connections/connection.php"); 
error_reporting(E_ALL^E_NOTICE); 

$userid = $_POST['userid']; 
$password = $_POST['password']; 
$submitted = $_POST['submitted']; 
if ($userid && $password){ 
    $query =sprintf("SELECT * FROM users where user_name= '$userid' and user_password = '$password'"); 
    $result [email protected]_query($query); 
    $rowAccount [email protected]_fetch_array($result); 
} 
if ($rowAccount){ 
    echo "The record exists so you can enter "; 

} elseif($submitted){ 
    print "you don't exist in the system!"; 
} 


?> 

我的HTML:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Untitled Document</title> 
</head> 
<body> 
<form id="form1" name="form1" method="post" action="<?php $_SERVER['PHP_SELF'];?>"> 
    <table width="800"> 
    <tr> 
     <th width="233" scope="col">User ID </th> 
     <th width="555" scope="col"><p> 
     <label for="userid"></label> 
     <label for="userid"></label> 
     <input type="text" name="userid" id="userid" /> 
     </p> 
     <p>&nbsp; </p></th> 
    </tr> 
    <tr> 
     <td>Password </td> 
     <td> <label for="userid"></label>  <label for="password"></label> 

     <input type="text" name="password" id="password" /> </td> 
    </tr> 
    <tr> 
     <td>&nbsp;</td> 
     <td> <input type="hidden" name="submitted" id="submitted" />  <input type="submit" name="Submit" id="Submit" value="Submit" /></td> 
    </tr> 
    </table> 
</form> 
</body> 
</html> 

得到迴音工作的人必須給隱藏字段添加一個值,它的工作原理是

+0

你'elseif'語句只檢查的'$彥博值[「提交」]',而不是是否有任何記錄... – BenM 2013-04-08 17:44:37

+0

貴隱場「提交」保存任何形式的價值? – 2013-04-08 17:44:40

+0

HTML和PHP代碼都在同一個文件中?如果是,那麼消息可能正在打印,但您只能使用瀏覽器的查看源選項來查看。嘗試在消息之後使用die()... – 2013-04-08 17:45:11

回答

0

嘗試改變

elseif($submitted){ print "you don't exist in the system!"; }

簡單:

else(){ print "you don't exist in the system!"; }

,看看你看到你的消息呢?

您正在檢查一個沒有值的變量,因此它返回false並且不會觸發elseif語句。

或者,你可以在你的HTML部分更改爲類似:

<input type="hidden" name="submitted" id="submitted" value="test" />

你可以看到我已經給它的測試值,現在只是讓以解僱你的ELSEIF語句返回true 。

+0

我不得不改變我的html文本爲 Michael 2013-04-08 18:00:56