Welcome Guest, Not a member yet? Register   Sign In
Help session grab user_id from database
#41

[eluser]the_unforgiven[/eluser]
I've commented out the loop and still nothing all it shows it username doesn't grab anything else in the getCust() query
#42

[eluser]the_unforgiven[/eluser]
anyone?
#43

[eluser]Samus[/eluser]
I made some mistakes as Chronix pointed out.

Code:
Login Check:

// Logged In
function check()
{
  
    
  $this->form_validation->set_rules('username', 'required|max_length[15]');
  $this->form_validation->set_rules('password', 'required|sha1');
    
  if ($this->form_validation->run() == FALSE) {
  
   $data['title'] = "Customer Login";
   $this->load->view('user/logon', $data);
  }
  else {

// Check user and password
  $query = $this->user_model->checkUser($this->input->post('username'), sha1($this->input->post('password')));
   if($query['true']) {
    
     $result = $query['row'];
    
         $session_data = array(
           'username'     => $result['username'],
           'is_user'      => true,
           'is_logged_in' => true,
           'last_login'   => time(),
           'customer_id'  => $result['id'],
           'acc_number'   => $result['acc_number'],
           'name'         => $result['name']
                );
  
     $this->session->set_userdata($session_data);
     redirect('user/myaccount');
      }
   }
   else {
    // username or password incorrect, should probably create a callback instead
   }
  }
}

Code:
function checkUser($username, $password)
{

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

  if($query->num_rows() == 1)
  {
    $data['true'] = TRUE;
    $data['result'] = $query->row_array();
  }
  else {
    $data['true'] = FALSE;
  }
return $data;
}
#44

[eluser]the_unforgiven[/eluser]
Am getting
Code:
Severity: Notice

Message: Undefined index: row

Filename: controllers/user.php

Line Number: 57

On line 57 is"
Code:
$result = $query['row'];
#45

[eluser]Samus[/eluser]
[quote author="the_unforgiven" date="1338310358"]Am getting
Code:
Severity: Notice

Message: Undefined index: row

Filename: controllers/user.php

Line Number: 57

On line 57 is"
Code:
$result = $query['row'];
[/quote]
I'm bound to make mistakes when i'm not coding for myself, you should try debug for yourself once in a while. Smile

Code:
function checkUser($username, $password)
{

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

  if($query->num_rows() == 1)
  {
    $data['true'] = TRUE;
    $data['row'] = $query->row_array();
  }
  else {
    $data['true'] = FALSE;
  }
return $data;
}
#46

[eluser]the_unforgiven[/eluser]
apologies i did the mistake after all.
#47

[eluser]the_unforgiven[/eluser]
Sorry I also forgot my manners @Samus and the rest who contributed to helping me, thanks a million....

Smile
#48

[eluser]kesty[/eluser]
[quote author="Samus" date="1337788344"]
Code:
if($query) {
$result = $this->user_model->getCustomer();
foreach($result as $res) {
    $data = array(
                 'username'    => $this->input->post('username'),
     'is_user'     => true,
     'last_login'  => time(),
     'customer_id' => $res['id'], // assuming your db column name is 'id'
     'acc_number'  => $res['acc_number'],
     //'cust_id'     => $this->session->userdata('id') What's happening here? :S
              );
}

model
Code:
function getCustomer()
{
   $data = array();

   $Q = $this->db->get('users');
   if ($Q->num_rows() > 0){
        $data = $Q->result_array();
   }
     $Q->free_result();    
     return $data;
}

Let me know how that works[/quote]
i am not really in support with this ur idea, because it is not only going to return id but everything in the users table
#49

[eluser]the_unforgiven[/eluser]
Which is what I wanted it to do, so its fine all work perfectly now!




Theme © iAndrew 2016 - Forum software by © MyBB