$wpdb->update has finished saving trigger?

I have a custom table that I am updating via wp_ajax action. I am inserting a row and inserting all of the values other than id which is an AUTO_INCREMENT. I have an ajax response that creates a new row on the page with the new data. In my response I need to see if the row was added, and then get the record to display. I can of course print everything other than the id with the variables I have pre defined, but I want to get the dynamically created digit as well! Help! I need an if statement to see when the row has finished saving.

The trouble is here in my php, specifically getting $carrier_id:

<?php
add_action('wp_ajax_change_carrier', 'carrier_change_callback');
function carrier_change_callback() {
    global $wpdb;

    //New Carrier
    if ($_POST['newCarrier']){
        $wpdb->insert( 
            $wpdb->prefix.'bf_carriers', 
            array( 
                'name' => stripslashes($_POST['newName']), 
                'label' => $_POST['newLabel'],
                'service_center_path' => $_POST['newHtm'],
                'image_name' => $_POST['newImage']
            )
        );
        //set the variables to return the new Table Row
        $carrier_name = stripslashes($_POST['newName']);
        $carrier_image = $_POST['newImage'];
        $carrier_label = $_POST['newLabel'];
        $carrier_htm = $_POST['newHtm'];
        $carrier_id = $wpdb->get_row("SELECT id FROM $wpdb->prefix.'bf_carriers' WHERE image_name = $carrier_image");
?>
        <tr>
        <!-- Lots of junk going on in here to display above variables and return the response to my ajax call -->
        </tr>
<?php   
    die();
    }
}

Related posts

1 comment

  1. After an insert, the ID generated for the AUTO_INCREMENT column can be accessed with:

    $wpdb->insert_id
    

    Last sentence is just copyed and pasted form the codex.

Comments are closed.