By iamwhoiam on
Hi everyone, I'm currently using the following code to assign roles to "paid" users in a function. The users are automatically assigned "unpaid" role, rid=7, on registration. I want to change it to "paid", rid=6, in this function.
The following bit of code successfully does this.
the variable $uid is available
$result = db_query("DELETE FROM {users_roles} WHERE uid=%d AND rid=7", $uid, $rid);
if ($result)
{
watchdog('fee', "Removed 'Unpaid' role from user $name (User $uid, $mail)");
}
else
{
watchdog('fee', "Failed to remove 'Unpaid' role from $name (User $uid, $mail)");
}
$result = db_query("INSERT INTO {users_roles} (uid, rid) values (%d, 6)", $uid, $rid);
cache_clear_all($uid .':', 'cache_menu', TRUE);
if ($result)
{
drupal_set_message("You have been successfully marked as paid.");
watchdog('fee', "Added 'Paid' role to user $name (User $uid, $mail)");
}
else
{
drupal_set_message("We have failed to verify your payment. Please email us.");
watchdog('fee', "Failed to add 'Paid' role to $name (User $uid, $mail)");
}
However, I want to use the function user_save to do this to maintain compatibility across other modules.
Please can someone help me
Comments
Please do not cross-post.
Please do not cross-post.
Don't reply to this thread, see http://drupal.org/node/384490.