skip to Main Content

In my knowledge, I have done everything correctly. I can confirm that the table name is correct(aupair_registered_employee_prefferred_countries), ID is correct. I dont understand why it fails. Also, the "last_error and "last_query" are no help. it cant detect the error. At this point I dont know how to move forward with this.

function update_employee($request){
    global $wpdb;
    $data = array(
        'wp_user_id'   => 70,
        'country'      => 'Sloveniax',
        'is_activated' => 1,
        'year_created' => 2020,
    );
    $where      = array('ID' => 27);
    $result     = $wpdb->update('aupair_registered_employee_prefferred_countries', $data, $data_where);
    if($result){
        wp_send_json_success("SUCCESS : ".$wpdb->last_error);
    } else {
        wp_send_json_error("ERROR21 : ".$wpdb->last_error." RESULT ".$result);
    }
    die();
}

//aupair_registered_employee_prefferred_countries
enter image description here

Can anyone shed some light on me on this one!!!!

2

Answers


  1. Chosen as BEST ANSWER

    I used "$data_where" instead of just "$where". Also, if somebody has this issue make sure that before updating, you have udpated any value. Wordpress update wont trigger unless there is any value that is updated.


  2. You should pass $wpdb->prefix to table name.

    function update_employee($request){
        global $wpdb;
        $data_update = array(
            'firstname' => $request['firstName'],
            'lastname'  => $request['lastName'],
        );
        $data_where = array('ID' => '7');
        $result     = $wpdb->update($wpdb->prefix.'aupair_registered_employee', $data_update, $data_where);
        if($result){
            wp_send_json_success("SUCCESS : ".$wpdb->last_error);
        } else {
            wp_send_json_error("ERROR : ".$wpdb->last_query);
        }
        die();
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search