致命错误调用数字函数no.of行

时间:2016-05-30 09:21:00

标签: php mysql codeigniter

public function email_check()
    {
        $this->form_validation->set_message('email_check', 'The %s '.$this->input->post('usr_email').' is already exist');
        $this->db->where('usr_email', $this->input->post('usr_email'));
        $query = $this->db->get('users');
        if ($query->num_rows()>0)
            return false;
        else
            return true;      


    }
  

(!)致命错误:在a上调用成员函数num_rows()   在线上C:\ wamp \ www \ application \ controllers \ users.php中的非对象   264

调用堆栈

#   Time    Memory  Function    Location
1   0.0005  266584  {main}( )   ..\index.php:0
2   0.0015  324704  require_once( 'C:\wamp\www\\system\core\CodeIgniter.php' )  ..\index.php:202
3   0.0440  4030256 call_user_func_array:{C:\wamp\www/\system\core\CodeIgniter.php:359} ( ) ..\CodeIgniter.php:359
4   0.0440  4031120 Users->save_registration( ) ..\CodeIgniter.php:359
5   0.0440  4044000 CI_Form_validation->run( )  ..\users.php:302
6   0.0450  4056264 CI_Form_validation->_execute( ) ..\Form_validation.php:341
7   0.0450  4057600 Users->email_check( )   ..\Form_validation.php:593

2 个答案:

答案 0 :(得分:0)

如果要对唯一电子邮件地址进行验证。请执行以下操作

$this->form_validation->set_rules('email', 'email', 'required|is_unique[tablename.fieldname]');

答案 1 :(得分:0)

我认为你做错了。 试试这个。

$result = $this->db->where('usr_email', $this->input->post('usr_email'))
                   ->get('users')
                   ->num_rows();

if($result > 0)
{
     return false; // value you want true or false
}
else
{
     return true; // value you want true or false
}