thinkphp会员登录问题
<?php
session_start();
header('Content-Type:text/html; charset=utf-8');
class AdminAction extends Action{
public function index(){
if(isset($_POST['username'])){
if(isset($_POST['username'])&&isset($_POST['password'])){
$db=M();
$select=$db->query("select * from developers where username=".$POST['username']." and password=".$_POST['password']."");
if($select){
$_SESSION['admin']=$_POST['username'];
$this->redirect('Index/index','',2,'用户'.$_POST['username'].'登录成功!');
}else{
$this->redirect('Index/index','',2,'用户名或者密码不正确');
}
}else{
$this->redirect('Index/index','',2,'用户名或密码不能为空!');
}
}
$this->display();
}
}
?>
这是AdminAction代码,不知道怎么回事,不管输入什么或者不输人它都提示用户名或者密码不正确,为什么呢?哪的问题?
[解决办法]
看看sql语句在数据库的查询结果有没有问题。
[解决办法]
你确定你的sql没错??
"select * from developers where username='".$POST['username']."' and password='".$_POST['password']."'"
[解决办法]
查询操作后面加上: echo $db->getLastSql();exit; 把sql语句打印出来就知道结果了。
[解决办法]
表单里的name属性有没有写错
[解决办法]
查询操作后面加上: echo $db->getLastSql();exit; 把sql语句打印出来就知道结果了。
用这个发现问题了,username不管我输入什么都打印不出来,password就没问题,这是哪的问题呢?没发现是哪写错了啊
表单里的name属性有没有写错
当然不可能写错了。。。怎么会犯那么低级的错误...
你的password没有MD5?
[解决办法]
是不是数据库里md5了,查询里没有md5
[解决办法]
你直接打印$_POST看看有没有username
[解决办法]
先获取post值看下,再输出sql,再把sql执行,看是否返回结果集。
[解决办法]
检查一下浏览器 cookie
[解决办法]
username='".$POST['username']."'
发现问题了没
username='".$_POST['username']."'