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
<?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
));
}
}
?>
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- You must be logged in to reply to this topic.