嗨,我刚刚使用 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> </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> </td>
<td> <input type="hidden" name="submitted" id="submitted" /> <input type="submit" name="Submit" id="Submit" value="Submit" /></td>
</tr>
</table>
</form>
</body>
</html>
要使回声正常工作,必须向隐藏字段添加一个值并且它起作用了