Welcome Guest, Not a member yet? Register   Sign In
Login2
#11

[eluser]davy_yg[/eluser]
I think I find the error but still do not know how to code the login right.

I wonder how should I code it?

If this is the formula:

$this->db->where('tablename');
$this->db->get('tablename');

This is my table:
ids_user

username
password
user_email
user_fname
user_address
user_phone

I basically needs to check if the password is the same as the inputed data.
#12

[eluser]Tpojka[/eluser]
You missed one parameter in where clause.
Code:
$this->db->where('column', $request);

User guide.
#13

[eluser]davy_yg[/eluser]
ok, this is what I tried. Is this correct?

controllers/clogin.php

Code:
public function process(){
        
        $username = $this->input->post('username', TRUE);  
        $password = $this->input->post('password', TRUE);

        // Load the model
        $this->load->model('Login_model');
        // Validate the user can login
        $result = $this->Login_model->validate($username, $password); // here you send data to model
        // Now we verify the result
        if(! $result){
            // If user did not validate, then show them login page again
            $this->index();
        }else{
            // If user did validate,
            // Send them to members area
            redirect('admin/admin');
        }        
}

model/login_model.php

Code:
public function validate($username, $password){ // same data you have sent from controller
  
        // Prep the query
        $this->db->get_where('ids_user', $username);
        $this->db->get_where('ids_user', $password);
        
        // Run the query
        $query = $this->db->get('ids_user');
        // Let's check if there are any results
        if($query->num_rows() == 1)
        {
            // If there is a user, then create session data
            $row = $query->row();
            $data = array(
                    'username' => $row->username,
     'password' => $row->password,
                    'validated' => true
                    );
            $this->session->set_userdata($data);
            return true;
        }
        // If the previous process did not validate
        // then return false.
        return false;
    }
}
#14

[eluser]Tpojka[/eluser]
[quote author="davy_yg" date="1383141929"]Is this correct?
[/quote]
Is that working for you?
#15

[eluser]davy_yg[/eluser]


A PHP Error was encountered

Severity: Notice

Message: Undefined property: Clogin::$db

Filename: core/Model.php

Line Number: 51

----------------------------------------

I receive this error message:

Fatal error: Call to a member function get_where() on a non-object in C:\xampp\htdocs\IndonusaCI\application\models\login_model.php on line 18

line 18: $this->db->get_where('ids_user', $username);




Theme © iAndrew 2016 - Forum software by © MyBB