Welcome Guest, Not a member yet? Register   Sign In
passing in user id to retrieve user data after login
#1

[eluser]swgj19[/eluser]
I am having a challenging time with this. I created a db table. In that table is an id and a user_id. I am putting together a login password retrieval system. The part I am working on now is the member's logged in page. When the user logs in, I need to be able to retrieve all the users profile data.
I am able only to retrieve the table memberships first row thus far. I need to retrieve the persons data who logs in based on the id passed when they signed up for membership. Currently I know that the id being passed into the form in the view is wrong.

These are the steps that I need to do below:
Add a user_id to your profile table and make it a key.
Then you can grab the users profile by their user id.
So when you create the users profile assign the users id to the profile users id.

Please give me direction in where I am missing it.

Here is my db table:

Code:
CREATE TABLE `membership` (
  `id` int(11) NOT NULL auto_increment,
  `user_id` int(11) NOT NULL,
  `first_name` varchar(25) NOT NULL,
  `last_name` varchar(25) NOT NULL,
  `username` varchar(25) NOT NULL,
  `password` varchar(32) NOT NULL,
  `email_address` varchar(50) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=27 ;

Here is my new function in my Membership_model to get the user id:

Code:
function retrieve_user($id = '')
     {
     $this->db->where('id', $id);  // get users record
     $q = $this->db->get('membership');   // this would be changed to your users table name

      if($q->num_rows() > 0) {
        // return a single db row array $row['name'];
        return $q->row_array();
        // return a single db object $row->name;
        // return $q->row;      
      }
      return FALSE;
Here is my view. I do not know how to pass the hidden user id when new member is created:

Code:
<h3>Create an Account!</h3>
<fieldset>
<legend>Personal Information</legend>
&lt;?php
  
echo form_open('login/create_member');

echo form_input('first_name', set_value('first_name', 'First Name'));
echo form_input('last_name', set_value('last_name', 'Last Name'));
echo form_input('email_address', set_value('email_address', 'Email Address'));
?&gt;
</fieldset>

<fieldset>
<legend>Login Info</legend>
&lt;?php
echo form_input('username', set_value('username', 'Username'));
echo form_input('password', set_value('password', 'Password'));
echo form_input('password2', 'Password Confirm');
echo form_hidden('id', $whatever['id']);  //This is where I do not know how to pass in the id

echo form_submit('submit', 'Create Acccount');
?&gt;

&lt;?php echo validation_errors('<p class="error">'); ?&gt;
</fieldset>

Here is my controller. I know I need to pass a variable in my method to pass back into the view to pass into the database. Then I will some how compare the inputed user id to the users user_id.

Code:
function members_profile()
   {
     $this->load->model('Membership_model');
  //pull data
    $data = $this->Membership_model->retrieve_user($id);
    $data = $this
  //load the view and pass the data to it
    $this->load->view('signup_form', $data);
   }


Messages In This Thread
passing in user id to retrieve user data after login - by El Forum - 06-01-2012, 04:40 PM
passing in user id to retrieve user data after login - by El Forum - 06-01-2012, 08:55 PM
passing in user id to retrieve user data after login - by El Forum - 06-01-2012, 09:25 PM
passing in user id to retrieve user data after login - by El Forum - 06-01-2012, 09:29 PM
passing in user id to retrieve user data after login - by El Forum - 06-01-2012, 10:46 PM
passing in user id to retrieve user data after login - by El Forum - 06-01-2012, 10:47 PM
passing in user id to retrieve user data after login - by El Forum - 06-02-2012, 12:32 AM
passing in user id to retrieve user data after login - by El Forum - 06-02-2012, 08:16 AM
passing in user id to retrieve user data after login - by El Forum - 06-02-2012, 01:54 PM



Theme © iAndrew 2016 - Forum software by © MyBB