making multiple wpdb->get_var() calls results in wordpress database error

I’m having trouble with updating records in my database table. I’m developing a wordpress plugin that uses jQuery AJAX requests on a form. I am working on the final submit action. Upon submit button click I send my data to my function, then I want to check to make sure that:

1.) The email address is in my database table
2.) Get a total count of Day and Boat entries from my table

Once I make sure the email address exists in my database and that there are available boats on the day they selected, then I want to update my database table. It is not updating. What am I doing wrong?

Here is the code:

function validate_submit_input() {

global $wpdb;

$emailIni = $_POST['email'];
$codeIni = $_POST['code'];
$dayIni = $_POST['day'];
$boatIni = $_POST['boat'];

$submitStatus = false;

$emailFinal = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->base_prefix}signups WHERE Email = '$emailIni' ");
global $wpdb;
$countFinal = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->base_prefix}signups WHERE Day = '$dayIni' AND Boat = '$boatIni' ");

if($boatIni = 'c'){
    if( (intval($emailFinal) > 0) && (intval($countFinal) < 20)){
        $wpdb->show_errors();
        $insert = $wpdb->update( $wpdb->wp_signups, array("Email" => $emailIni, "Code" => $codeIni, "Day" => $dayIni, "Boat" => $boatIni ) );
        $wpdb->print_error();
    }
} else if ($boatIni = 'k'){
    if( (intval($emailFinal) > 0) && (intval($countFinal) < 68)){
        $wpdb->show_errors();
        $insert = $wpdb->update( $wpdb->wp_signups, array("Email" => $emailIni, "Code" => $codeIni, "Day" => $dayIni, "Boat" => $boatIni ) );
        $wpdb->print_error();
    }
} else if ($boatIni = 't'){
    if( (intval($emailFinal) > 0) && (intval($countFinal) < 12)){
        $wpdb->show_errors();
        $insert = $wpdb->update( $wpdb->wp_signups, array("Email" => $emailIni, "Code" => $codeIni, "Day" => $dayIni, "Boat" => $boatIni ) );
        $wpdb->print_error();
    }
} else {
    echo "Error in boat type";
}

if ( $submitStatus ) {
    echo "Registration Successful";
} else {
    echo $emailFinal . " " . $countFinal;//"Registration Still Available";
}
exit;

}

Both $emailFinal and $countFinal return the values I would need to satisfy the If statements controlling the update queries. Here’s the output from debug.log:

[20-Apr-2017 15:31:21 UTC] PHP Notice: Undefined property: wpdb::$wp_rei_signups in /var/www/html/wordpress5/wp-includes/wp-db.php on line 684
[20-Apr-2017 15:31:21 UTC] PHP Warning: Missing argument 3 for wpdb::update(), called in /var/www/html/wordpress5/wp-content/plugins/jrei-plugin/jrei-plugin.php on line 111 and defined in /var/www/html/wordpress5/wp-includes/wp-db.php on line 2022
[20-Apr-2017 15:31:21 UTC] PHP Notice: Undefined variable: where in /var/www/html/wordpress5/wp-includes/wp-db.php on line 2023
[20-Apr-2017 15:31:21 UTC] WordPress database error for query SELECT COUNT(*) FROM wp_signups WHERE Day = ‘1’ AND Boat = ‘t’ made by do_action(‘wp_ajax_validate_submit’), WP_Hook->do_action, WP_Hook->apply_filters, validate_submit_input

Read more here: making multiple wpdb->get_var() calls results in wordpress database error

Leave a Reply

Your email address will not be published. Required fields are marked *