我在我的登录中有这个代码,然后我尝试输入我的密码,例如我的真实密码是" Reymar25",但当我输入" reymar25"它登录,它不应该继续在其他页面。 ,请帮我恢复这个..谢谢你
<?php
include('dbconnection.php');
if (isset($_POST['submit']))
{
$username = $_POST['username'];$password = $_POST['password'];
$query = mysql_query("SELECT * FROM tbl_user username = '".$username."' AND password = '".$password."' LIMIT 1");
//("SELECT * FROM tbl_user WHERE username = '".$username."' AND password = '".$password."' LIMIT 1");
if (mysql_num_rows($query) == 1)
{
$row = mysql_fetch_array($query);
header("Location: index1.php"); // Modify to go to the page you would like
exit;
}
else
{
header("Location: loginform.php");
echo "Please Check Username or Password!";
exit();
}
}
?>
答案 0 :(得分:2)
检查用户名和密码列的排序规则设置。见http://dev.mysql.com/doc/refman/5.0/en/case-sensitivity.html
(请阅读有关您问题的评论,其中包含有关如何解决代码中其他问题的重要信息)
答案 1 :(得分:0)
关于这个问题:
为什么要重复两次SQL语句? 但是查询是正确的。我想你可能需要使列区分大小写。请参阅this回答。
然而,您实施的机制非常弱:
答案 2 :(得分:0)
我尝试了这段代码并且有效。对不起,如果我不使用PDO,
if (isset($_POST['submit']))
{
$username = $_POST['username'];
$password = $_POST['password'];
$query = mysql_query("SELECT * FROM tbl_user LIMIT 1");
while($row = mysql_fetch_array($query))
{
if(strcmp($username,$row['username'])==0 && strcmp($password,$row['password'])==0)
{
header("Location: index1.php");
}
else
{
echo "Somethings wrong either on your Username or Password Please Try Again" ;
}
}
} ?&GT;