How to assign roles in my own registration form
function company_form()
    {
         $form['company_username'] =  array(
          '#type' =&gt; 'textfield',
          '#title' =&gt; 'company-username',
          '#default_value' =&gt; '',
              '#required'=&gt;'true' 
      );  
          $form['company_email'] =  array(
          '#type' =&gt; 'textfield',
          '#title' =&gt; 'company-email',
              '#required'=&gt;'true', 
          '#default_value' =&gt; '',
          '#element_validate' =&gt; array('generate_special_form_validate'),
      );  
           $form['company_password'] =  array(
          '#type' =&gt; 'textfield',
          '#title' =&gt; 'company-password',
               '#required'=&gt;'true', 
          '#default_value' =&gt; ''
      );  

      $form['submit'] =  array(
          '#type' =&gt; 'submit',
          '#title' =&gt; '',
          '#value' =&gt; 'Submit',
          '#default_value' =&gt; ''
      );
      return $form;
    }
    function company_form__validate(&amp;$form_state,$form) {

         if (!valid_email_address($form['input']['email'])) {
         form_set_error($form['input']['email'],'Please enter a valid email address.');
       }
    }
    function company_form_submit($form, &amp;$form_state)
    {


     global $user;
        $company_username = $form_state['input']['company_username'];
        $company_email = $form_state['input']['company_email'];
        $company_password = $form_state['input']['company_password'];        
         $fields = array(
              'name' =&gt; $company_username,
              'pass' =&gt;$company_password,
              'mail' =&gt; $company_email,
              'init' =&gt; $company_email,
              'status' =&gt; 1,
              'access' =&gt; REQUEST_TIME,
              'roles' =&gt; array(
               4 =&gt; 'company',
                ),

        );
        $account=user_save('', $fields);  


    if($account-&gt;uid)
    {
     drupal_set_message('User Created SuccessFully');
    }

}


Firstly you have to create roles from backend.
and then You can Assign as many roles by passing role id and role name in array.

'roles' =&gt; array(
               4 =&gt; 'company',
                ),


Hope this code helps you.