• 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)
  • '$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.
Viewing 1 replies (of 1 total)

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