-1

My code just for save the data session.

This is my code:

$idfb = 12121983918 // just sample id.

$sql = $this->db->query('SELECT * from user WHERE facebookid = "'.$idfb.'" LIMIT 1');
$datalogin = $sql->row();
$loginsession= array(

    'jenis_user' =>$datalogin->jenis_user, // the problem is here, i got eror in here, the errors is Trying to get property of non-object .
    'photo'=>$datalogin->photo,
    'facebookid'=>$datalogin->facebookid, 
    'id'=>$datalogin->id, 
    'email'=>$datalogin->email, 
    'username'=>$datalogin->username, 
    'nama'=>$datalogin->nama,
    // 'jenis_user'=>$datalogin->jenis_user,
    'alamat'=>$datalogin->alamat,
    'no_telpon'=>$datalogin->no_telpon,
);

$this->session->set_userdata('loginsession',$loginsession);

redirect($this->agent->referrer());

I hope someone can solved this problem. Thanks! :)

Bertrand Martel
  • 42,756
  • 16
  • 135
  • 159
Gilang Pratama
  • 439
  • 6
  • 18

2 Answers2

1

It seems you are going right

Please double check your sql, make sure that you are using right table and column names.

and try replacing

$sql = $this->db->query('SELECT * from user WHERE facebookid = "'.$idfb.'" LIMIT 1');

with

<?php
$this->db->where('facebookid', $idfb);
$this->db->limit(1);
$sql = $this->db->get_where('user');
?>

if same error, try echo $sql->num_rows() to see if you are getting row or not.

Raman Saluja
  • 106
  • 1
  • 12
0

Since database structure is not given, I can assume the database query is returning 0 rows. Always try to handle exception.

$idfb = 12121983918; // just sample id.

 $sql = $this->db->query('SELECT * from user WHERE facebookid = "'.$idfb.'" LIMIT 1');
 if($sql->num_rows()>0){
        $datalogin = $sql->row();
        $loginsession= array(

            'jenis_user' =>$datalogin->jenis_user, // the problem is here, i got eror in here, the errors is Trying to get property of non-object .
            'photo'=>$datalogin->photo,
            'facebookid'=>$datalogin->facebookid, 
            'id'=>$datalogin->id, 
            'email'=>$datalogin->email, 
            'username'=>$datalogin->username, 
            'nama'=>$datalogin->nama,
            // 'jenis_user'=>$datalogin->jenis_user,
            'alamat'=>$datalogin->alamat,
            'no_telpon'=>$datalogin->no_telpon,
            );

        $this->session->set_userdata('loginsession',$loginsession);

        redirect($this->agent->referrer());
  }
  else
  {
        Your Code
  }
Bikram Pahi
  • 1,107
  • 1
  • 12
  • 33