Welcome Guest, Not a member yet? Register   Sign In
Autoload Database not working
#3

[eluser]AntonioAntar[/eluser]
This is also what I have for my config

Code:
$config['base_url'] = 'http://localhost:1337/mysite/';
I changed the localhost:1337 to just localhost in my database.php file. The site is now loading, but the data is still not being retrieved from database.

What I have is a login portal. I want the users to input their email and password, and then I want the controller to check the database to see if the email and password exist, and if they do, the website will direct them to the 'members' page

if the email and password do not match, i want the message displayed 'Incorrect username/password'

I have sample emails and passwords stored in database, but when I input the email and password
in the database, the login portal always brings me back to the login page


This is my code

For my controller I have

Code:
public function login_validation(){
    
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
    $this->form_validation->set_rules('email','Email','required|trim|xss_clean|callback_validate_credentials');
    $this->form_validation->set_rules('password','Password','required|trim|xss_clean');
    
    if ($this->form_validation->run()){
        redirect('site/members');
    } else {
        $this->load->view('login-view');
        
    }
}
    
    public function validate_credentials() {
        $this->load->model('model_users');
        if ($this->model_users->can_log_in()){
            return true;
        } else {
            $this->form_validation->set_message('validate_credentials','Incorrect username/password.');
                    return false;
        }
    }

The part that isn't working in this code seems to be the validate_credentials part. I input the correct email and password, but the browser does not take me to the 'members page'

This is what I have for my model

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Model_users extends CI_Model {
    
    Public Function can_log_in() {
        $this->load->database();
        $this->db->where('email', $this->input->post('email'));
        $this->db->where('password',($this->input->post('password')));
        $query = $this->db->get('users');
        
        if ($query->num_rows() == 1) {
            return true;
        } else {
            return false;
        }
    }
}

The table I'm trying to pull the email and password from is called users


Messages In This Thread
Autoload Database not working - by El Forum - 07-14-2014, 11:39 AM
Autoload Database not working - by El Forum - 07-14-2014, 11:42 AM
Autoload Database not working - by El Forum - 07-14-2014, 12:11 PM
Autoload Database not working - by El Forum - 07-14-2014, 12:14 PM



Theme © iAndrew 2016 - Forum software by © MyBB