Welcome Guest, Not a member yet? Register   Sign In
login problem

You appear you may have a few issues going on. Try to keep your model functions to only be doing db stuff. Leave the redirects and such out. It will help you later on. Here is a sample of revising some of your code. Hopefully this will help out some. Be sure to check out the user guide and read about the MVC structure. I regret not reading the guide as thoroughly when I first started. It made it a pain to go back and update some of the code.
//Login Controller
    function index(){
            if ($this->session->userdata('logged_in') == TRUE)
              redirect('addressbook/index'); //You are already logged in
            //Set up form validation / required fields
            //Create form data with repopulating fields
            $data['username'] = array('id' => 'username', 'name' => 'username', 'value' => set_value('username'));
            $data['password'] = array('id' => 'password', 'name' => 'password', 'value' => set_value('password'));
                //Check submitted login
                $user = $this->address_model->validate($this->input->post('username'),$this->input->post('password'));
                if(!$user) //user failed try again
                //Otherwise send user to address book
              //Display login form to user
    //Addressbook Controller
    function index(){
        if ($this->session->userdata('logged_in') != TRUE)
              redirect('login/index'); //You are not already logged in
        $data['c'] = $this->address_model->index_get();
    function validate($username1,$password1)
        $query = $this->db->get_where('addressbook', array('email' => $username1,'password1'=>$password1));// change db to addressbook
        if($query->num_rows() > 0){
            $row = $query->row(0); //Set data from first row retrieved
            $data = array('username'    =>  $row->username1,
                            'logged_in' =>  TRUE,
                            'flag'      =>  TRUE);
            $this->session->set_flashdata('message','You have sucessfully logged in.');
            return TRUE;
        return FALSE;
    //Login Form
    <?php echo $this->load->view('header');?>

    <?php echo form_open('login/index') . ā€œ\nā€; ?>
      <div id="message">&lt;?php echo $this->session->flashdata('message'); ?&gt;</div>

      <label for="username">Username: </label>&lt;?php echo form_input($username); ?&gt;
      <label for="password">Password: </label>&lt;?php echo form_password($password); ?&gt;
      &lt;input type="submit" value="Submit" /&gt;&lt;/p>
     &lt;?php echo anchor('addressbook','Back'); ?&gt;

      &lt;?php echo form_close(); ?&gt;

Messages In This Thread
login problem - by El Forum - 04-17-2010, 03:56 AM
login problem - by El Forum - 04-17-2010, 10:06 AM
login problem - by El Forum - 04-17-2010, 11:59 AM
login problem - by El Forum - 04-17-2010, 10:08 PM

Theme © iAndrew 2016 - Forum software by © MyBB