how to add form data in database
You'll need to define an ajax callback. This callback function can then be called by the form, and can submit values to the database for you using the Drupal database layer. In this case, I imagine the ajax handler will be added to the Next or Submit button.

$form['next'] = array(
  '#type' =&gt; 'submit',
  '#value' =&gt; t('Submit'),
  '#ajax' =&gt; array(
    'callback' =&gt; 'custom_ajax_callback'
  ),
);


Your module might also want to define its own database table to store temporary values for this.