Title: WordPress database does not update with my code
Last modified: October 30, 2017

---

# WordPress database does not update with my code

 *  [ohdude](https://wordpress.org/support/users/ohdude/)
 * (@ohdude)
 * [8 years, 7 months ago](https://wordpress.org/support/topic/wordpress-database-does-not-update/)
 * Hey everyone,
 * I am trying to update my mysql wp database.
    I have this code, it compares withu
   the date how is selected. But it won’t update. Is the query wrong?
 *     ```
       $mydate = date('Y-m-d', strtotime($date));
   
       global $wpdb;
   
               $wpdb->update( 
                   'wpxt_availability', 
                   array( 
                       'Available' => 'false',	// string
                       'first_name' => $_POST['Firstname'],	// string
                       'last_name' => $_POST['Lastname'],	// string
                       'Phone' => $_POST['Phone'],	// string
                       'Email' => $_POST['Email'],	// string
                       'Extra' => $_POST['Extra'],	// string             
   
   
   
                   ), 
                   array( 'Date' => '$mydate'  ), 
                   array( 
                       '%s',	// value1
   
                   ), 
                   array( '%d' ) 
               );
               Echo "Aangepast";
               echo $mydate;
       ```
   

Viewing 1 replies (of 1 total)

 *  [Jacob Peattie](https://wordpress.org/support/users/jakept/)
 * (@jakept)
 * [8 years, 7 months ago](https://wordpress.org/support/topic/wordpress-database-does-not-update/#post-9633130)
 * `'$mydate'` is going to literally compare to the string `$mydate`. Use `$mydate`
   directly.
 * For the format argument (the 2nd argument), you’ve only provided formats for 
   the first value. You need to specify 6 formats, or if they’re all strings, just
   pass `%s` as a string.
 * Also, you’re using `%d` to format the `WHERE` value, which is `$mydate`. You’ve
   formatted as `Y-m-d` though, which is not going to be an integer, which is was`%
   d` formats for.
 * So the update should look like:
 *     ```
       $wpdb->update( 
       	'wpxt_availability', 
       	array( 
       		'Available'  => 'false',
       		'first_name' => $_POST['Firstname'],
       		'last_name'  => $_POST['Lastname'],
       		'Phone'      => $_POST['Phone'],
       		'Email'      => $_POST['Email'],
       		'Extra'      => $_POST['Extra'],
       	), 
       	array( 
       		'Date' => $mydate,
       	), 
       	'%s', 
       	'%s'
       );
       ```
   
    -  This reply was modified 8 years, 7 months ago by [Jacob Peattie](https://wordpress.org/support/users/jakept/).

Viewing 1 replies (of 1 total)

The topic ‘WordPress database does not update with my code’ is closed to new replies.

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 1 reply
 * 2 participants
 * Last reply from: [Jacob Peattie](https://wordpress.org/support/users/jakept/)
 * Last activity: [8 years, 7 months ago](https://wordpress.org/support/topic/wordpress-database-does-not-update/#post-9633130)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
