-2

こんにちは、php と mysql を使用してログイン システムを作成しました。データベースから有効なユーザー名とパスワードを入力すると、ログイン システムが機能しますが、無効なユーザー名とパスワードを入力すると、それを言っているにもかかわらず、ログイン ページにループ バックします。ログインが失敗した場合に印刷したい失敗 ここに私のコードファイルがあります

<?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 =@mysql_query($query);
    $rowAccount =@mysql_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>

エコーを機能させるには、隠しフィールドに値を追加する必要があり、機能しました

4

1 に答える 1

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 を返すように、テスト値を与えていることがわかります。

于 2013-04-08T17:52:59.853 に答える