Welcome Guest, Not a member yet? Register   Sign In
Call to a member function num_rows() on a non-object
#1

[eluser]brixxster[/eluser]
Hello Guys, here I am again, the newbie Smile

I have this code in the controller which captures an email from a form. I wanted to check if the email is already in the database and show "email found" if it is indeed found. The problem I get a

Quote:Call to a member function num_rows() on a non-object
. What do you think I am doing wrong here sirs?


Thanks.


The Controller
Code:
$this->load->model('model_pwreset');
    $testEmail = $this->input->post('email');
    $emailCheck = $this->model_pwreset->pw_getemail($testEmail);
            
    if($emailCheck->num_rows() > 0 ){
        echo "email found";
    }

The Model

Code:
function pw_getemail($email)
    {
        $this->db->select('email');
        $this->db->from('account');
        $this->db->where('email', $email);
        
        $this->db->get();
    }
#2

[eluser]Sarfaraz Momin[/eluser]
a small mistake here in your model

Code:
function pw_getemail($email)
    {
        $this->db->select('email');
        $this->db->from('account');
        $this->db->where('email', $email);
        
        return $this->db->get();
    }

if you do not return anything from you model function that instance in the object is not created hence it is not going to work. change the code to the one above and it should work if rest things are in place.

- Sarfaraz
#3

[eluser]brixxster[/eluser]
Thanks very much Sarfaraz Momin! That worked out fine and thanks for the explanation, now I know. Smile




Theme © iAndrew 2016 - Forum software by © MyBB