php mysql写登陆注册的网页,验证用户输入的密码和数据库中保存的密码是否一致时的问题。
代码是:<?php$Username=$_POST['Username'];$Password=$_POST['Password'];$con=mysqli_connec...
代码是:
<?php
$Username=$_POST['Username'];
$Password=$_POST['Password'];
$con=mysqli_connect("127.0.0.1","root","19930126liujia","my_db");
if(mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result=mysqli_query($con,"SELECT * FROM Users WHERE Username='$Username'");
if($row=mysqli_fetch_array($result))
{
if($Password == $row['Password'])
echo "Congratulations!Login is successful!";
else
{
echo "Sorry!The password you entered is incorrect!<br>";
echo "<br/>";
echo "Please click here to try again:";
exit("<a href='http://127.0.0.1/Login.html'>Relogin</a>");
}
}
?>
为什么即使输入的密码是正确的还是显示登录失败!求大神解。。。 展开
<?php
$Username=$_POST['Username'];
$Password=$_POST['Password'];
$con=mysqli_connect("127.0.0.1","root","19930126liujia","my_db");
if(mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result=mysqli_query($con,"SELECT * FROM Users WHERE Username='$Username'");
if($row=mysqli_fetch_array($result))
{
if($Password == $row['Password'])
echo "Congratulations!Login is successful!";
else
{
echo "Sorry!The password you entered is incorrect!<br>";
echo "<br/>";
echo "Please click here to try again:";
exit("<a href='http://127.0.0.1/Login.html'>Relogin</a>");
}
}
?>
为什么即使输入的密码是正确的还是显示登录失败!求大神解。。。 展开
2014-08-23
展开全部
吧$Password和$row['Password']输出出来看下,不过一般不这样验证,直接吧帐号和密码带入mysql中查询是否有记录即可。
追问
$Password中的内容可以输出来,为什么$row['Password']中的内容输不出来啊?
把密码存到数据库里,他会自动用MD5加密么?
追答
不会,需要在插入数据库前加密,你说$row['Password']内容无法输出可以使用var_dump($row);看下,一般这种情况应该是查询的结果出问题了。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |