Welcome Guest, Not a member yet? Register   Sign In
How to store facebook user data into database ?
#6

[eluser]Anonymous[/eluser]
[quote author="Keloo" date="1337770467"]Not sure I understand.

I've tried something like this:
Code:
function account()
{
  $fb_data = $this->session->userdata('fb_data');

  if((!$fb_data['uid']) or (!$fb_data['me']))
  {

   redirect('home/index');
  }
  else if($this->db->get('users')->num_rows() < 0){
    $query = array(
    'uid' => $fb_data['uid'],
    'fullname' => $fb_data['me']['name'],
    'email' => $fb_data['me']['email']
   );

    $this->db->insert('users',$query);
   }
   else
   {

     $data = array(
      'fb_data' => $fb_data

    );

    $this->layouts->set_title('My Account');
    $this->layouts->view('account', $data);
   }

  }

It seems that it's working, and I can access the account page.

But is it ok ? How should I improve it ?

I'm trying to get the data, only the first time the user has logged in with facebook and accessed his account.

I don't know how should I make it work in another way.[/quote]

You have made the email column a unique key in your DB and you are trying to insert another entry with the same key.

With $this->db->get('users')->num_rows() < 0 you are just querying the users table for all rows.

Change this:
Code:
else if($this->db->get('users')->num_rows() < 0){

To something that DOES check if the supplied email is already in the database. Eg:

Code:
else if($this->users_model->getUserByEmail($fb_data['me']['email'])->num_rows() < 0){


Messages In This Thread
How to store facebook user data into database ? - by El Forum - 05-23-2012, 02:10 AM
How to store facebook user data into database ? - by El Forum - 05-23-2012, 02:33 AM
How to store facebook user data into database ? - by El Forum - 05-23-2012, 03:54 AM
How to store facebook user data into database ? - by El Forum - 05-24-2012, 01:44 AM
How to store facebook user data into database ? - by El Forum - 05-24-2012, 03:28 AM
How to store facebook user data into database ? - by El Forum - 05-24-2012, 06:32 AM
How to store facebook user data into database ? - by El Forum - 05-24-2012, 08:03 AM



Theme © iAndrew 2016 - Forum software by © MyBB