Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

How can I add points directly to the User Points database? I have a quiz site and would like to use the User Points module to store quiz scores, instead of creating something from scratch. I have created a taxonomy "Quiz" for such points.

Every quiz ends by showing the score made (between 0 to 100 depending on how many answers they got right). I would like to go on and store this in the userpoint database.

I am using the following code but m getting 2 error messages:

Notice: Undefined variable: user in ...
Notice: Trying to get property of non-object in ....

The code I am using is the following one:

$params = array (
  'uid' => $user->uid,
  'description' => 'Totals points from quizes',
  'points' => $percentage,
  'tid' =>127,
);

userpoints_userpointsapi($params);
share|improve this question
add comment

1 Answer

Userpoints has an API.

See especially userpoints_userpointsapi() Something like this: userpoints_userpointsapi(array('uid'=>$some_user, 'points'=>9000));

You might also be interested in the Quiz module which supports Userpoints.

share|improve this answer
    
Thanks. I found the following code which is working fine except am getting the following 2 errors. (I editted main code to include this errors + code. –  Albert Mar 12 '12 at 0:18
    
Well, looks like you have no defined $user object, you need to define the uid who should receive the points somehow. –  Berdir Mar 19 '12 at 0:43
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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