0

I added custom column in users table, i would like to use user_save to create new user programmatically. How can i do that? This code doesn't work for custom columns:

$new_user = array(
                        'name' => 'Foo',
                        'pass' => $pwd,
                        'mail' => $email,
                        'signature_format' => 'filtered_html',
                        'status' => 1,
                        'language' => 'en',
                        'timezone' => 'Europe/Berlin',
                        'init' => $email,
                        'custom' => $custom_string,
                        'roles' => array(
                            DRUPAL_AUTHENTICATED_RID => 'authenticated user',
                            $role->rid => $role->name,
                        ),
                    );

                    $new_account = user_save(NULL, $new_user);

Everything except custom gets inserted, if i am not wrong it's default drupal columns for each user's table. Thanks

3
  • Have you added the new column in a Drupal way or manually on the database?
    – webmaniac
    Oct 4, 2016 at 22:01
  • Hello, manually in the table's structure. What is the drupal way? fields for user?
    – patrik
    Oct 4, 2016 at 22:02
  • I hope the answer below is helpful.
    – webmaniac
    Oct 4, 2016 at 22:08

1 Answer 1

0

Manually adding extra columns in tables will rarely work for Drupal as there are dependencies and references that have to be honoured.

The correct way would be something along the lines of this case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.