我想用php验证登录,为什么无论密码是否正确都显示用户名或密码不正确

这是我的php代码:
<html>
<head>
<title>logincheck</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
</head>
<?php
$input=$_POST;
$link=mysqli_connect('localhost','root','123456789','news');
if(!$link) die('Connect Error:'.mysqli_connect_error());
$sql="select username,password from login where username = '{$input['username']}' and password = '{$input['password']}'";
$result = mysqli_query($link,$sql);
if(!$result) die('Query Error:'.$SQL);
$num = mysqli_num_rows($result);
if($num){
$row = mysqli_fetch_array($result,MYAQLI_ASSOC);
echo "欢迎您,$row[0]";

}else{
echo" <script>alert('用户名或密码不正确');history.go(-1);</script>";
}
?>
</html>

在mysqli_query之前使用var_dump($sql);输出sql语句,然后使用phpmyadmin或者mysql-cli执行下看看sql语句是否有问题。追问

使用var_dump($sql);后显示string(73)"select username,password from login where username=''and password=''",是因为post传值没有传过来么?

追答

在这句$input=$_POST;后面使用:

var_dump($input);看看输出

温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网