> For the complete documentation index, see [llms.txt](https://docs.super-forms.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.super-forms.com/developers/code-examples/insert-form-data-into-a-custom-database-table.md).

# Insert form data into a custom database table

In case you also want to clean up these rows when an entry is deleted you might want to read how to [delete a database row after an entry is deleted](/developers/code-examples/delete-database-row-after-contact-entry-is-deleted-in-wordpress.md).

```php
add_action('super_before_email_success_msg_action', '_super_save_data_into_database', 10, 1);
function _super_save_data_into_database( $atts ) {

    // REPLACE 123 WITH YOUR FORM ID
    $id = 123;

    // REPLACE table_name WITH YOUR TABLE NAME
    $table = 'table_name';

    // CHANGE THE BELOW ARRAY AND ADD COLUMNS AND FIELDS ACCORDINGLY
    $fields = array(
        'column_name' => 'first_name', // replace column_name with correct column name for your table, and first_name with the appropriate field name from your form
        'column_name2' => 'last_name', // replace column_name with correct column name for your table, and first_name with the appropriate field name from your form
        // etc...
    );

    $form_id = absint($atts['post']['form_id']); // contains the form ID that was submitted
    if( $form_id == $id ) {
        global $wpdb;
        $data = $atts['data']; // contains the submitted form data
        $values = array();
        foreach( $fields as $k => $v ) {
            $values[$k] = $data[$v]['value'];
        }
        $values['entry_id'] = absint($atts['entry_id']);
        $wpdb->insert( $table, $values );
    }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.super-forms.com/developers/code-examples/insert-form-data-into-a-custom-database-table.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
