Title: $wpdb-&gt;update
Last modified: August 19, 2016

---

# $wpdb->update

 *  [jlknauff](https://wordpress.org/support/users/jlknauff/)
 * (@jlknauff)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/wpdb-update/)
 * I’m having a problem with $wpdb->update (code below) throwing an error: unexpected
   T_STRING
 * Any idea what might be wrong here?
 *     ```
       $wpdb->update('wp_network_members', $insert_member_data WHERE 'f_name' = $insert_member_data['f_name'] AND 'l_name' = $insert_member_data['l_name']);
       ```
   

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Thread Starter [jlknauff](https://wordpress.org/support/users/jlknauff/)
 * (@jlknauff)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/wpdb-update/#post-1986320)
 * I realized I was missing a comma and don’t seem to need the single quotes on 
   the field names, but I’m still getting the same error. Here is my updated line
   of code:
 *     ```
       $wpdb->update('wp_network_members', $insert_member_data, WHERE f_name = $insert_member_data['f_name'] AND l_name = $insert_member_data['l_name']);
       ```
   
 *  [GRAQ](https://wordpress.org/support/users/graq/)
 * (@graq)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/wpdb-update/#post-1986336)
 * Try popping the clause in a variable first?
 *     ```
       $where = "WHERE f_name = {$insert_member_data['f_name']} AND l_name = {$insert_member_data['l_name']}'"
       $wpdb->update('wp_network_members', $insert_member_data, $where);
       ```
   
 *  [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * (@t31os_)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/wpdb-update/#post-1986407)
 * Could do with seeing an example of what’s in the `$insert_member_data` array,
   obviously
    aside from `f_name` and `l_name`.
 * That said, i think the update should look something like this..
 *     ```
       $wpdb->update(
           'wp_network_members', // Table
           $insert_member_data, // Array of key(col) => val(value to update to)
           array(
               'f_name' => $insert_member_data['f_name'],
               'l_name' => $insert_member_data['l_name']
           ) // Where
       );
       ```
   
 * ..which should be inline with the example here.
    [http://codex.wordpress.org/Function_Reference/wpdb_Class#Examples_7](http://codex.wordpress.org/Function_Reference/wpdb_Class#Examples_7)
 * Without knowing more about what’s in `$insert_member_data` though it’s hard to
   say if the query needs further adjustment(it will do if any the columns you’re
   updating are numeric columns – or something not a string).
 * You might find it easier to use `$wpdb->query` alongside `$wpdb->prepare`, so
   you can do your own `UPDATE foo WHERE bar`, etc.. without the fiddly formats 
   you’d have to contend with using `$wpdb->update`.
 *  Thread Starter [jlknauff](https://wordpress.org/support/users/jlknauff/)
 * (@jlknauff)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/wpdb-update/#post-1986415)
 * I found the solution – I replaced the two items that the WHERE statement was 
   using with an array of the two values and now it works fine.
 * Example:
 *     ```
       $wpdb->update('wp_network_members', $insert_member_data, $insert_member_data_match);
       ```
   

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘$wpdb->update’ is closed to new replies.

## Tags

 * [$wpdb-&gt;update](https://wordpress.org/support/topic-tag/wpdb-gtupdate/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 4 replies
 * 3 participants
 * Last reply from: [jlknauff](https://wordpress.org/support/users/jlknauff/)
 * Last activity: [15 years, 2 months ago](https://wordpress.org/support/topic/wpdb-update/#post-1986415)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
