我的表单验证有问题,一切正常,除非它检查用户名也可以,但检查用户名是否可以在插入表之前和之后使用,所以继续获取用户名是不可用的 代码看起来像这样
Function get()
{
$error = array();
$sth = $this->db->prepare('SELECT * FROM user WHERE username = :user');
$sth->execute(array(':user' => $_POST['username']));
$count = $sth->rowCount();
If($count > 0)
{
$error['avaliable'] = 'The username is not avaliable';
}
If(!empty($error))
{
Return $error;
}else{
//insert codes goes here
}
}
答案 0 :(得分:1)
你的控制声明在这里是错误的。试试这样的事情,
Function get()
{
$error = array();
$sth = $this->db->prepare('SELECT * FROM user WHERE username = :user');
$sth->execute(array(':user' => $_POST['username']));
$count = $sth->rowCount();
If($count == 0)
{
//insert codes goes here
}
else If($count > 0)
{
$error['avaliable'] = 'The username is avaliable';
}
If(!empty($error))
{
Return $error;
}
}