CyberJunkie
CyberJunkie

Reputation: 22674

Codeigniter help with user registration script

:) This question is for anyone familiar with the Tankauth plugin.

I edited tankauth so that user profiles are populated without email validation.

In the registration form I added and validated two more fields named “first_name” and “last_name” which I want to add to the user_profiles table when the form is submitted.

Below is the tankauth function that adds the user id to the user_profiles table if user is activated. I commented out if ($activated). The problem is that I don’t know how to insert my new fields first_name and last_name to the db. I keep getting errors for anything I try.

function create_user($data, $activated = TRUE)
    {
        $data['created'] = date('Y-m-d H:i:s');
        $data['activated'] = $activated ? 1 : 0;

        if ($this->db->insert($this->table_name, $data)) {
            $user_id = $this->db->insert_id();
            //if ($activated)
            $this->create_profile($user_id);
            return array(
                         'user_id' => $user_id,
                         'first_name' => $first_name, //added by me
                                                 'first_name' => $first_name, //added by me
                         );
        }
        return NULL;
    } 

The above is connected with

private function create_profile($user_id) 
    {
        $this->db->set('user_id', $user_id);
        $this->db->set('first_name', $first_name); //added by me
        return $this->db->insert($this->profile_table_name);
    } 

Can someone please share some guidance?

Upvotes: 0

Views: 569

Answers (1)

Bill
Bill

Reputation: 85

Try removing the private in private function create_profile

Also you might want to change your create_profile function to be:

function create_profile( $user_id ) {
    $data = array(
        'user_id' => $user_id,
        'first_name' => $first_name // Hopefully this is being set correctly.
    );

    return $this->db->insert( $this->profile_table_name, $data );
}

If none of those work. Try using echo $this->db->last_query();

Hope that helps.

Upvotes: 1

Related Questions