perhaps a new answer on an old post. But what you getting is an error on this part:
$wpdb->update()
this is because the variable $wpdb
is nog defined.
To get this working, you should place global $wpdb;
at the beginning of your function. like:
function after_wpai_post_saved($id) {
global $wpdb;
// get custom field