• global $wpdb;
    $db_name=$wpdb->someone;
    $id=5;
    $result =1;
    $note='Test note';
    
    $data=array(
    		                'is_success'=>$result,
    		                'note'=>$note,
    		                'success_time'=>date("Y-m-d H:i:s"),
    	          );
    
    $where=array(
                                    'id' => $id
                         );
    $format = array(
                                   '%d',
                                   '%s',
                                   '%s'
                           );
    $where_formart = array(
    
                                    '%d'
                           );
    
    $ok = $wpdb->update($db_name,$data,$where,$format,$where_formart);

    I want to update 3 fields,but it only update the 'success_time' field,and $ok is true,why?
    PS: all fields to be updated allow null.
    Did you know?

Viewing 1 replies (of 1 total)
  • Suggest that you check that the field have the correct spelling, and are correct UPPER/lower case.
    Also when a date+time field is updated with NULL, it sets the value to the present time, so the only field that is being updated may be updated for the wrong reason.
    The result $ok is a number, how many rows were updated

    More details here:
    http://codex.wordpress.org/Class_Reference/wpdb#UPDATE_rows

    This is how I would do this update:

    $q = $wpdb->prepare(‘UPDATE %s SET is_success = %d, note = %s, success_time = NULL WHERE id = %d’, $wpdb->someone, $result, $note, $id);
    $r = $wpdb->query($q);

Viewing 1 replies (of 1 total)
  • The topic ‘HELP:$wpdb->update only update only value.’ is closed to new replies.