index.html
<form method="post" action="__URL__/login" class="vf lf" style="margin-top:50px">
<table cellspacing="0" cellpadding="0" class="loginform">
<tr>
<th>账 号:</th>
<td><input type="text" name="loginname" class="t_input" /></td>
</tr>
<tr>
<th>密 码:</th>
<td><input type="password" name="password" class="t_input" /></td>
</tr>
<tr>
<td></td>
<td>
<input type="submit" class="button1" name="btnsubmit" value="登录后台" class="submit" /> <a href="__APP__/register">返回前台</a>
</td>
</tr>
</table>
</form>
indexAction.class.php
class IndexAction extends Action
{
/**
+----------------------------------------------------------
* 默认操作
+----------------------------------------------------------
*/
public function index()
{
$CustomerInfo =M('Customerinfo');
$this->display();
}
public function login()
{
$username = $_POST['loginname'];
echo $username;
$userpass = $_POST['password'];
$CustomerInfo=D('Customerinfo')->where("email='$username' AND pwd='$userpass'")->find();
if($CustomerInfo)
{
echo '<script>parent.location.href="/admin.php?s=/Index"</script>';
}
else
{
$this->redirect("index");
}
}
}
点登陆时能触发login()事件
能得到$_Post的值
但是问题是$CustomerInfo=D('Customerinfo')->where("email='$username' AND pwd='$userpass'")->find();
这一句返回 $CustomerInfo变量返回是空,应该怎么办?写错语句了吗?
<form method="post" action="__URL__/login" class="vf lf" style="margin-top:50px">
<table cellspacing="0" cellpadding="0" class="loginform">
<tr>
<th>账 号:</th>
<td><input type="text" name="loginname" class="t_input" /></td>
</tr>
<tr>
<th>密 码:</th>
<td><input type="password" name="password" class="t_input" /></td>
</tr>
<tr>
<td></td>
<td>
<input type="submit" class="button1" name="btnsubmit" value="登录后台" class="submit" /> <a href="__APP__/register">返回前台</a>
</td>
</tr>
</table>
</form>
indexAction.class.php
class IndexAction extends Action
{
/**
+----------------------------------------------------------
* 默认操作
+----------------------------------------------------------
*/
public function index()
{
$CustomerInfo =M('Customerinfo');
$this->display();
}
public function login()
{
$username = $_POST['loginname'];
echo $username;
$userpass = $_POST['password'];
$CustomerInfo=D('Customerinfo')->where("email='$username' AND pwd='$userpass'")->find();
if($CustomerInfo)
{
echo '<script>parent.location.href="/admin.php?s=/Index"</script>';
}
else
{
$this->redirect("index");
}
}
}
点登陆时能触发login()事件
能得到$_Post的值
但是问题是$CustomerInfo=D('Customerinfo')->where("email='$username' AND pwd='$userpass'")->find();
这一句返回 $CustomerInfo变量返回是空,应该怎么办?写错语句了吗?
变量用单引号括起来之后它就代表一个字符串,而不是变量
$CustomerInfo=D('Customerinfo')->where("email=$username AND pwd=$userpass")->find();
$CustomerInfo还是返回false
把输出的sql语句直接放mysql里面运行一次看有没有提示错误?
$mod=D('Customer');
$CustomerInfo=$mod->where("userName='$username' AND pwd='$userpass'")->find();
$mod->getlastsql();
改成这样就可以,
$mod=D('Customer');
$CustomerInfo=$mod->where("userName='$username' AND pwd='$userpass'")->find();
echo $mod->getlastsql(); //这个就是获取执行的SQL