Title: Insert Into Another Table
Last modified: August 19, 2024

---

# Insert Into Another Table

 *  Resolved [Mattmcca](https://wordpress.org/support/users/mattmcca/)
 * (@mattmcca)
 * [1 year, 9 months ago](https://wordpress.org/support/topic/insert-into-another-table/)
 * Hello I am trying to insert a value from a submitted form into another table,
   for some reason I am unable to insert into the other table, any assistance would
   be appericated. Below is my code
 *     ```wp-block-code
       <?php/*** Plugin Name: [FluentForms] - Fluent Forms Insert Into Database After Form Submission * Description: Charge dealer dependent on the number of bookings they have made.* Author: Matthias McCarthy* License: GPLv2 or later* Version: 1.0.0*/add_action('fluentform/submission_inserted', 'charge_dealer_submission_function', 20, 2);function charge_dealer_submission_function($entryId, $formId){    global $wpdb;    $numberOfBookings = 0;    $current_user = get_current_user_id();    // Get the submission data using the entry ID    $submissionData = wpFluent()->table('fluentform_submissions')->find($entryId);    // Extract form fields    $formFields = wpFluent()->table('fluentform_submission_meta')                            ->where('submission_id', $entryId)                            ->get();    foreach ($formFields as $field) {        $fieldName = $field->meta_key;        $fieldValue = $field->value;        // Check if the field is the one we're interested in        if ($fieldName == 'numeric_field') {  // Corrected from 'field_name' to 'meta_key'            $numberOfBookings = intval($fieldValue);        }    }    // Insert into Credit_Log if numberOfBookings is greater than 0    if ($numberOfBookings > 0) {        $wpdb->query($wpdb->prepare(            "INSERT INTO Credit_Log (Credits, Action, User_ID, PerformedBy)              VALUES (%d, %s, %d, %d)",            -$numberOfBookings,      // Credits (negative for deduction)            'Transaction',           // Action            $current_user,           // User_ID            $current_user            // PerformedBy        ));    }}?>
       ```
   
    -  This topic was modified 1 year, 9 months ago by [Mattmcca](https://wordpress.org/support/users/mattmcca/).
      Reason: More Info

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Plugin Support [Amimul Ihsan](https://wordpress.org/support/users/amimulihsanmahdi/)
 * (@amimulihsanmahdi)
 * [1 year, 9 months ago](https://wordpress.org/support/topic/insert-into-another-table/#post-17964286)
 * Hello [@mattmcca](https://wordpress.org/support/users/mattmcca/),
 * While we always strive to assist with general inquiries and ensure you get the
   most out of Fluent Forms, providing support for custom code solutions falls outside
   the scope of our support services.
 * We recommend seeking help from a developer who can assist with custom code implementations
   like the one you’re working on.
 * We appreciate your understanding, and if you have any questions about Fluent 
   Forms’ built-in features or configurations, feel free to ask!
 * Thank you
 *  Thread Starter [Mattmcca](https://wordpress.org/support/users/mattmcca/)
 * (@mattmcca)
 * [1 year, 9 months ago](https://wordpress.org/support/topic/insert-into-another-table/#post-17965235)
 *     ```wp-block-code
       <?php/*** Plugin Name: [FluentForms] - Fluent Forms Insert Into Database After Form Submission * Description: Charge dealer dependent on the number of bookings they have made.* Author: Matthias McCarthy* License: GPLv2 or later* Version: 1.0.0*/add_action('fluentform/submission_inserted', 'charge_dealer_submission_function', 20, 3);function charge_dealer_submission_function($submissionId, $formData, $form){    if($form->id != 3) {      return;   }    global $wpdb;    $numberOfBookings = 0;    $current_user = get_current_user_id();    $numberOfBookings = $wpdb->get_var($wpdb->prepare(      "SELECT value FROM krv_fluentform_entry_details WHERE submission_id = %d AND field_name = %s",      $submissionId,      'numeric_field'    ));}?>
       ```
   
 * Let me update the question then as i found some of the issues. Every time I submit,
   $submissionId is returning as null in my code. is there something that I am missing
 *  Plugin Support [Amimul Ihsan](https://wordpress.org/support/users/amimulihsanmahdi/)
 * (@amimulihsanmahdi)
 * [1 year, 9 months ago](https://wordpress.org/support/topic/insert-into-another-table/#post-17965841)
 * Hello there,
 * We have tested the hook submission_inserted on our end and it seems to be working
   fine, the $submissionId is printed perfectly; please check the [screenshot](https://prnt.sc/uE145DNi6Wsm).
 * Thank you
 *  Thread Starter [Mattmcca](https://wordpress.org/support/users/mattmcca/)
 * (@mattmcca)
 * [1 year, 9 months ago](https://wordpress.org/support/topic/insert-into-another-table/#post-17965945)
 * Hi thank you so much I will carry on investigating the issue, I would like to
   ask . Am I able to use the following items in add_action, since two of these 
   variables are wordpress functions
 *     ```wp-block-code
         global $wpdb;   $numberOfBookings = 0;   $current_user = get_current_user_id();
       ```
   
 *  Thread Starter [Mattmcca](https://wordpress.org/support/users/mattmcca/)
 * (@mattmcca)
 * [1 year, 9 months ago](https://wordpress.org/support/topic/insert-into-another-table/#post-17967666)
 * Hi I managed to solve this issue thank you for all the help that was provided

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Insert Into Another Table’ is closed to new replies.

 * ![](https://ps.w.org/fluentform/assets/icon-256x256.png?rev=3354580)
 * [Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder](https://wordpress.org/plugins/fluentform/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/fluentform/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/fluentform/)
 * [Active Topics](https://wordpress.org/support/plugin/fluentform/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/fluentform/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/fluentform/reviews/)

## Tags

 * [database](https://wordpress.org/support/topic-tag/database/)
 * [sql](https://wordpress.org/support/topic-tag/sql/)

 * 5 replies
 * 2 participants
 * Last reply from: [Mattmcca](https://wordpress.org/support/users/mattmcca/)
 * Last activity: [1 year, 9 months ago](https://wordpress.org/support/topic/insert-into-another-table/#post-17967666)
 * Status: resolved