How Can I Make My Registration Module Save_Users

I have downloaded a Registration Module and added a username and password fields to the form.

I am trying to call the Save_User function from within the hook_form_alter() as shown in the code.

However I keep getting message “duplicate entry ” for key ‘name’ insert into users”. This led me to see that the field $form_state[‘value’][‘field_username’] was empty, that is the value is not being passed in the Post action. I ahve also tried

function mymodule_form_alter(&$form, &$form_state, $form_id)
if (isset($form[‘actions’][‘submit’])) {
$form[‘actions’][‘submit’][‘#submit’][] =’mymodule_form_submit’;

return $form;

function mymodule_form_submit(&$form, &$form_state)
$user_info = array(
‘name’ => $form_state[‘value’][‘field_username’],
‘pass’ => $form_state[‘value’][‘field_confirm_password’],
‘mail’ => $form_state[‘value’][‘field_email’],
‘status’ =>1,
‘init’ => $form_state[‘value’][‘field_email’],
user_save(null, $user_info);


Note: I have also tried:

$user_info = array(
‘name’ => $form_state[‘values’][‘field_username’],
‘pass’ => $form_state[‘values’][‘field_confirm_password’],
‘mail’ => $form_state[‘values’][‘field_email’],
‘init’ => $form_state[‘values’][‘field_email’],
‘status’ =>1,

Drupal version: