0

I want to create a membership number for every new user that registers on my site. I want the membership number to include the userID so i can connect it back in the future.

The only way I can find to do this is by using db_insert into the field table. I can no longer login as user 1. Is there any reason i can't do this? Is there a cleaner way, and are there any other dependent tables?

function ican_user_insert(&$edit, $account, $category) {
$randomnumber=rand(100,999);
$membernumbercalc='LT'.$edit['uid'].$randomnumber;
db_insert('field_data_field_membership_number')
->fields(array(
'entity_type'=>'user',
            'bundle'=>'user',
            'language'=>'und',
            'field_membership_number_value' => $membernumbercalc,
            'entity_id' => $account->uid,
            'delta'=>0,
            'deleted'=>0,
))
->execute();


}
gillarf
  • 114
  • 9
  • Why can't you change the $account (pass by reference)'s field_data_field_membership_number ? – AKS Jun 26 '12 at 03:08
  • Thanks, i'm sure I tried that first, but it didn't work (i don;t remember why). I think i just stuck with the above. It worked, but it seemed overkill to do it this way. – gillarf Aug 14 '12 at 13:39

0 Answers0