Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Data Update #13

Open
dhamaso opened this issue Feb 28, 2013 · 0 comments
Open

Custom Data Update #13

dhamaso opened this issue Feb 28, 2013 · 0 comments

Comments

@dhamaso
Copy link

dhamaso commented Feb 28, 2013

Hello again, When i try to update the user's data like this:

// Config Settings
$config['database']['user_acc']['custom_columns'] = array(
'first_name', 'last_name'
);

// Update Code
$user_id = 3;
$user_data = array(
'uacc_password' => 'newpass',
'first_name' => 'Damaso',
'last_name' => 'Pérez'
);

if(!$this->flexi_auth->update_user($user_id, $user_data)){
exit($this->flexi_auth->get_messages());
}

The library show me an sql error:
UPDATE user_accounts SET = 'Perez' WHEREuser_accounts.uacc_id` = '5'

This is because the custom_columns array's keys are numeric instead associative keys (the column names in the user account table):
print_r($user_account_cols);
Array
(
[id] => uacc_id
[group_id] => uacc_group_fk
[email] => uacc_email
[username] => uacc_username
[password] => uacc_password
...
[0] => first_name <-- check the key
[1] => last_name <-- check the key
)

So in the below code
foreach ($this->auth->database_config['user_acc']['custom_columns'] as $column) {
$user_account_cols[] = $column;
}

Change this
foreach ($this->auth->database_config['user_acc']['custom_columns'] as $column) {
$user_account_cols[$column] = $column;
}

Now the array keys are
print_r($user_account_cols);
Array
(
[id] => uacc_id
[group_id] => uacc_group_fk
[email] => uacc_email
[username] => uacc_username
[password] => uacc_password
...
[first_name] => first_name
[last_name] => last_name
)

And now change the line
$sql_update[$this->auth->tbl_col_user_account[$key]] = $user_data[$column];

by adding
if(array_key_exists($key, $this->auth->tbl_col_user_account)){
$sql_update[$this->auth->tbl_col_user_account[$key]] = $user_data[$column];
}else{
$sql_update[$key] = $user_data[$column];
}

This works for me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant