Welcome Guest, Not a member yet? Register   Sign In
Login model from 2009 not working in CI 2.02
#1

[eluser]Unknown[/eluser]
This code in my model is not working on version 2.02 of codeigniter,

This was written in a tutorial from 2009,

Anybody can see something wrong/that should be updated?

Code:
<?php

class Users extends CI_Model {
    
    function Users()
    {
        parent::__construct();
    }
    
    function login($username, $password)
    {

        $query = $this->db->get_where('users', array('username'=>$username, 'password'=>$password));

        if ($query->num_rows()==0) return false;
        else{
            $result = $query->result();
            $userid = $result[0]->id;

            return $userid;
        }

    }

}
#2

[eluser]InsiteFX[/eluser]
Code:
class Users extends CI_Model {
    
    // but this not need unless your setting things
    function __construct()
    {
        parent::__construct();
    }
    
    function login($username, $password)
    {

        $query = $this->db->get_where('users', array('username'=>$username, 'password'=>$password));

        if ($query->num_rows()==0) return false;
        else{
            $result = $query->result();
            $userid = $result[0]->id;

            return $userid;
        }

    }

}

InsiteFX
#3

[eluser]theprodigy[/eluser]
I can't seem to find anything wrong with what you have other than the constructor, as InsiteFX pointed out.
Can you post the controller code that you are using to access it?
Maybe there is something in there that isn't correct.




Theme © iAndrew 2016 - Forum software by © MyBB