I have the following code in my functions.php that deals with the processing of a Gravity form input.
[php]
//Study registration post data to custom tables
add_action(‘gform_after_submission_3’, ‘post_to_third_party’, 10, 2);
function post_to_third_party($entry, $form) {
global $wpdb;
$member = sanitize_user($entry[“1”]);
$study = sanitize_text_field(strtolower($entry[“2”]));
$website = esc_url($entry[“3”]);
$abt = sanitize_text_field($entry[“16”]);
$dna = sanitize_text_field($entry[“17”]);
$worldwide = sanitize_text_field($entry[“4”]);
if ($worldwide==“yes”){
$country = “Worldwide”;
}
else {
$country = sanitize_text_field($entry[“5”]);
}
$SQL = “INSERT INTO ts14_studies( study_name, mem_no, worldwide, country, website, abt, dna) VALUES ( ‘$study’ , ‘$member’, ‘$worldwide’, ‘$country’, ‘$website’, ‘$abt’, ‘$dna’)”;
$wpdb->query($SQL);
//Now get ID of the study entry
$study_id = $wpdb->get_col(“select ID from ts14_studies where study_name =’$study’ ORDER BY ID DESC LIMIT 1”);
// Now write to the variants table
// First write master surname
$variant = $study;
$SQL = “INSERT INTO ts14_variants( variant_name, study_id) VALUES ( ‘$variant’, ‘$study_id[0]’ )”;
$wpdb->query($SQL);
if ($entry["6"] == "Yes"){
//check fields 7-15 for variants and write to database
$x = 7;
while ($x<=15){
$variant = sanitize_text_field(strtolower($entry[$x]));
if ($variant == ""){
break;}
else {
$SQL = "INSERT INTO ts14_variants( variant_name, study_id) VALUES ( '$variant', '$study_id[0]' )";
$wpdb->query($SQL);
$x++;
}
}
}
}
[/php]
This works fine most of the time. Occasionally this code is not executed
[php]$SQL = “INSERT INTO ts14_studies( study_name, mem_no, worldwide, country, website, abt, dna) VALUES ( ‘$study’ , ‘$member’, ‘$worldwide’, ‘$country’, ‘$website’, ‘$abt’, ‘$dna’)”;
$wpdb->query($SQL);[/php]
Has anyone any ideas why this may be the case, I suspect there is a bug somewhere but I can’t spot it.