Running an update user meta data query with wpdb in wordpress

Hi i tried to use wordpresses update_user_meta() function but it kept giving me issues so i had to use this solution

First include the global


global $wpdb;

Then run this query obviously change the values to yours


$var = ltrim($_POST['example']);
$user_id = ltrim($_POST['user_id']);

if($wpdb->query("UPDATE wp_usermeta SET meta_value = '".$var."' WHERE meta_key = 'example' AND user_id = ".$user_id."")){