1

I use this code for login_model:

  • class Login_model extends CI_Model{

    function __construct(){
        parent:: __construct();
    }
    
    function check(){
        $username = $this->input->post('username',true);
        $password = $this->input->post('password',true);
        $remember = $this->input->post('remember',true);
    
    
        /*
        $this->db->select('username','username');
        $this->db->select('password','password');
        $this->db->where('username',"$username");
        $this->db->where('password',md5($password));
        $this->db->from('user');
        $this->db->limit(1);
        $is = $this->db->count_all_results();
        */
        $user = $this->db->get_where ('user',array('username'=>$username,'password'=>md5($password)));
        $is = $user->num_row();
    
        if($is>0){
    
            $id = $user->row(0)->id;
            $data_session=array(
                'username'=>'$username',
                'login'=> true,
                'id'=>$id
            );
            $this->session->set_userdata($data_session);
    
            if($remember == 1){
               $login_text= $username.'_isLogin_'. $id;
                $this->load->library('encrypt');
                $cookie_value = $this->encrypt->encode($login_text,ENCRYPT_KEY);
    
               $data_cookie=array(
                   'name'=>'Ahmadreza',
                   'value'=>$cookie_value,
                   'expire'=>time()+60*60*24*365
               );
                $this->input->set_cookie($data_cookie);
            }
            redirect('post/index');
        }else{
            redirect('login/index');
        }
    
    
    }
    

    }

  • but show this ! error now how can I solve this problem.

    Thank you.

    Error Image : https://i.sstatic.net/MPQLX.png

    2
    • 1
      SOLVE just a litter problem from my code : i use $is = $user->num_row(); but i should used : $is = $user->num_rows(); i didnt use "s" after row just this Commented Jul 20, 2015 at 17:51
    • Assuming that code will just work is the main cause for errors. You need to always check for errors, where they can occur, even if you think nothing bad will happen. Commented Jul 20, 2015 at 17:53

    2 Answers 2

    5

    It is num_rows() and not num_row()

    Replace,

    $is = $user->num_row();
    

    with

    $is = $user->num_rows();
    
    Sign up to request clarification or add additional context in comments.

    Comments

    1

    there is no any function call num_row(); in Codeigniter.

    So correct way is num_rows(); num_rows() Function in Codeigniter

    So Final Well-form code is

    $is = $user->num_rows();
    

    Note :
    Not all database drivers have a native way of getting the total number of rows for a result set. When this is the case, all of the data is prefetched and count() is manually called on the resulting array in order to achieve the same result.

    Comments

    Your Answer

    By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.