title: How to assign role with PHP in Drupal?
body: <p>I need to assign a kind of "premium status" to members that purchase an amount equal or greater than 100 € via PHP.</p>
  
  <p>Conditional Actions are already set up (user = anonymous/authenticated AND total amount = equal/greater than 100 AND user =! premium) but I'm missing the PHP part to actually say "then grant him the premium membership". </p>
  
  <p>How can I achieve this?</p>
  
  <p>EDIT: is the below code correct?</p>
  
  <pre><code>if ($account) {
    $uid = $account-&gt;uid;
    $role_name = 'authenticated user';
    $rid = db_result(db_query("SELECT rid FROM {role} WHERE name = '%s'", $role_name));
    db_query("INSERT INTO {users_roles} (uid, rid) VALUES(%d, %d)", $uid, $rid);
    watchdog('user', 'uc ca added role to Ubercart created user');
  }
  </code></pre>