Error Using user.save

Events happening in the community are now at Drupal community events on www.drupal.org.
polliwog's picture

Using the user.save method I receive the following error:

user warning: Duplicate entry '' for key 2 query: INSERT INTO users (created, access) VALUES (1254426886, 1254426886) in htdocs/modules/user/user.module on line 327.

I'm using Drupal 6.14 and the lastest version of AMFPHP and the Services module.

Nothing I've tried seems to work, so yny help getting past this problem would appreciated.

Comments

Issue On Uid

alagirivimal's picture

Hi

 This is error mean entered user id not in database table.

 please enter uid = 1 and check.

 otherwise have issue reply i will help to you

new user register modules:
-========================

// user.add
array(
  '#method'           => 'user.add',
  '#callback'         => 'user_service_add',
  '#file'             => array('file' => 'inc', 'module' => 'user_service'),
  '#args'             => array(
    array(
      '#name'           => 'name',
      '#type'           => 'string',
      '#description'    => t('User Name.'),
    ),
    array(
      '#name'           => 'pass',
      '#type'           => 'string',
      '#description'    => t('User Password.'),
    ),
    array(
      '#name'           => 'mail',
      '#type'           => 'string',
      '#description'    => t('User Email.'),
    ),
 ),
  '#return'           => 'struct',
  '#help'             => t('Added user details.')
),

new user INC
==============

function user_service_add($name,$pass,$mail) {

$account_add = user_save($account,array('name' => $name, 'pass' => $pass, 'mail' => $mail, 'status' =>'1'));

if (!$account_add) {
return services_error(t('Error on saving the user.'));
}

return $account_add->uid;
}

Thanks for your reply, but

polliwog's picture

Thanks for your reply, but we've already decided to take another route with this project in order to bypass this problem

Hope you can share, we have

jomesili's picture

Hope you can share, we have been having this issue for some time, i haven't gotten past it yet

Unfortunately our solution

polliwog's picture

Unfortunately our solution did not fix the user.save problem. We gave up trying to make it work and instead hired someone who created new services specific to our project. These new services handle storing and retrieving data that we originally planned on storing in custom fields in a user's profile.

solution

jcunliffe's picture

The problem lies within the user module:
"if (is_object($account) && $account->uid) {"

Using AMFPhP you implicetly convert the user object to an array, which is_not_an_object.

So additional to the solution suggested elsewhere ([http://drupal.org/node/305826]), use in user_service.inc instead:
$account = (isset($account->uid) && is_object($account) ) ? user_save($account) : user_save('', $account);

And voila, it runs just fine.

Services

Group organizers

Group categories

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: