I have a problem with the $wpdb->update below. The var_dump data is correct but the update is not saving the data into the record of the table. Table name is wp_rdp_media_organisations. Unique field is media_org_id.

Has someone of you an idea what I do wrong here? Thanks in advance.


$media_org_id = '';
        'media_org_id'      => $media_org_id,
        'company_name'      => $company_name,
        'gender'            => $gender,
        'first_name'        => $first_name,
        'last_name'         => $last_name,
        'street_address'    => $street_address,
        'zipcode'           => $zipcode,
        'visit_addres'      => $visit_addres,   
        'visit_zipcode'     => $visit_zipcode,          
        'city'              => $city,
        'country'           => $country,
        'email_address'     => $email_address,
        'telephone'         => $telephone,
        'mobile_nr'         => $mobile_nr,
        'status'            => $status,         
        'comments'          => $comments,
        'last_updated'      => date("Y-m-d H:i:s")          
    array( 'media_org_id' => $row_id ), 
        '%d' ,
        '%s' ,
        '%s' ,
        '%s' ,
        '%s' ,
        '%s' ,
        '%s' ,
        '%s' ,
        '%s' ,
        '%s' ,
        '%s' ,
        '%s' ,
        '%s' ,
        '%s' ,
        '%d' ,
        '%s' ,      
    ) , 
    array( '%d' ) 
$msg = 'Record is updated sucessfully.';

array(17) { ["row_id"]=> string(2) "45" ["company_name"]=> string(22) "Media Bureau Lekker bv" ["gender"]=> string(4) "Male" ["first_name"]=> string(3) "Jan" ["last_name"]=> string(8) "de Vries" ["street_address"]=> string(12) "Postadres 12" ["zipcode"]=> string(6) "8923FG" ["visit_addres"]=> string(13) "Bezoekadres 4" ["visit_zipcode"]=> string(6) "8999DW" ["city"]=> string(10) "Lekkerveen" ["country"]=> string(9) "Nederland" ["email_address"]=> string(20) "info@BureauLekker.nl" ["telephone"]=> string(12) "435635464536" ["mobile_nr"]=> string(14) "33634565463456" ["status"]=> string(1) "0" ["comments"]=> string(74) "Nieuw beureau oppassen met credit geven. Betalen binnen 5 dagen is vereist" ["update_media_org"]=> string(10) "Update Now" } 
  • 1
    You should include Auth checks, and avoid using the extract function, especially when used on $_POST. What was the reason for using a custom table rather than a custom post type and post meta? – Tom J Nowell Jun 28 '16 at 11:17
  • The developer of this code explain to me that this is the right way todo. If there is a better way, please give me an example so I can try. The update is in admin not in front. – Hermants Jun 28 '16 at 11:19
  • I spend a lot of hours testing and reading all kinds of examples. Without any result. The dump is correct but no saving into table. Does somebody maybe has a solution? – Hermants Jun 28 '16 at 12:35
  • If debugging is disabled, you're gonna have a bad time. – TheDeadMedic Jun 28 '16 at 12:58
  • For the future, a custom post type with post meta and taxonomies would be the WP way to do this, custom tables should be avoided ( there are situations that warrant them sometimes e.g. traffic analytics ). What is the return value of the update call? – Tom J Nowell Jun 28 '16 at 13:07

When the following variable is empty,

$media_org_id = '';

it results in an empty record_id.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.