create a new user with content profile


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <?php
  2.  
  3. require_once './includes/bootstrap.inc';
  4. drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
  5.  
  6. $query = db_query("SELECT * FROM {OldUserTable}");
  7.  
  8. while ($row = db_fetch_array($query) )
  9. {
  10. $userData = array( 'name' => $row['ID'], 'pass' => $row['PASSWORD'], 'mail' => $row['EMAIL'], 'status' => 1, 'roles' => $role );
  11. try
  12. {
  13. $time = time();
  14. $new_user = user_save('', $userData);
  15. $good_count++;
  16.  
  17. try
  18. {
  19. $profile_node = new stdClass();
  20. $profile_node->title = $new_user->name;
  21. $profile_node->body = '';
  22. $profile_node->type = 'profile'; // Your specified content type
  23. $profile_node->created = $time;
  24. $profile_node->changed = $time;
  25. $profile_node->status = 1;
  26. $profile_node->promote = 0;
  27. $profile_node->sticky = 0;
  28. $profile_node->format = 1; // Filtered HTML
  29. $profile_node->uid = $new_user->uid; // UID of content owner
  30. $profile_node->field_first_name[0]['value'] = $row['FIRST'];
  31. $profile_node->field_last_name[0]['value'] = $row['LAST'];
  32. $profile_node->field_location[0]['street'] = $row['ADDRESS'];
  33. $profile_node->field_location[0]['city'] = $row['CITY'];
  34. $profile_node->field_location[0]['province'] = $row['STATE'];
  35. $profile_node->field_location[0]['postal_code'] = $row['ZIP'];
  36. $profile_node->field_location[0]['country_name'] = 'United States';
  37. $profile_node->field_location[0]['phone'] = $row['PHONE'];
  38. $profile_node->field_location[0]['fax'] = $row['FAX'];
  39.  
  40. node_save($profile_node);
  41. }
  42. catch (Exception $e)
  43. {
  44. echo 'Caught exception: ', $e->getMessage(), "\n";
  45. }
  46. }
  47. catch (Exception $e)
  48. {
  49. echo 'Caught exception: ', $e->getMessage(), "\n";
  50. }
  51. }
  52. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.