• Resolved MikeKJ

    (@mikekj)


    I am using this in a function to save a form input to a table

    $success = $wpdb->insert( $table_name, array( ‘Title’ => $title, ‘first_name’ => $firstname, ‘surname’ => $surname, ‘DOB’ => $dob, ‘Sex’ => $sex, ‘HouseNumberName’ => $housenumbername, ‘StreetRoad’ => $streetroad, ‘TownCityVillage’ => $towncityvillage, ‘CountyStateRegion’ => $countystateregion, ‘Postcode’ => $postcode, ‘country’ => $country, ‘Nationality’ => $nationality, ‘your_email’ => $youremail, ‘confirm_email_425’ => $youremail, ‘telephone’ => $telephone, ‘role’ => $role_string, ‘English_Level’ => $englishlevel, ‘photo1_path’ => $path1, ‘photo_1’ => $photo1, ‘photo_1_img’ => $imgContent1, ‘photo2_path’ => $path2, ‘photo_2’ => $photo2, ‘photo_2_img’ => $imgContent2, ‘previous_work’ => $previouswork, ‘year_last_worked’ => $yearlastworked, ‘Available_From’ => $availablefrom, ‘Available_To’ => $availableto, ‘bankaccount’ => $bankaccount, ‘IDL’ => $idl, ‘EnhancedLic’ => $enhancedlic_string, ‘OEL’ => $oel, ‘PassportID’ => $passportid, ‘NI’ => $ni, ‘accommodation’ => $accommodation, ‘Education’ => $education, ‘Experience’ => $experience, ‘Other’ => $other, ‘AccompanyingName1’ => $acc1, ‘Relationship1’ => $rel1, ‘AccompanyingEmail1’ => $accemail1, ‘confirm_email_775’ => $accemail1, ‘AccompanyingName2’ => $acc2, ‘Relationship2’ => $rel2, ‘AccompanyingEmail2’ => $accemail2, ‘confirm_email_776’ => $accemail2, ‘AccompanyingName3’ => $acc3, ‘Relationship3’ => $rel3, ‘AccompanyingEmail3’ => $accemail3, ‘confirm_email_777’ => $accemail3, ‘acceptance_323’ => $accept, ‘datestamp’ => $datetime ));

    I have checked that there are 51 columns excluding the auto-imcrementing primary key ‘id’ and that the field names are as per the table but it won’t write to the table, anyone have any idea why please?

Viewing 3 replies - 1 through 3 (of 3 total)
  • necafasu

    (@necafasu)

    Include global $wpdb; in your code

    • This reply was modified 7 years ago by necafasu.
    • This reply was modified 7 years ago by necafasu.
    RossMitchell

    (@rossmitchell)

    As necafasu said.
    Also enable debugging in your wp-config.php, find define('WP_DEBUG', false);
    and replace it with:
    define('WP_DEBUG', true);
    possibly also add:
    error_reporting(E_ALL); ini_set('display_errors', 1);
    Be sure to remove these when you are done, they are possible security and performance problems.

    Thread Starter MikeKJ

    (@mikekj)

    I had already set global $wpdb; and that debugging reported an uninitiated
    variable that I was using for error checking $error, so even though when I echoed that variable it reported as 0 (no errors) it must have been in an undertimnate state as when I initiated it as $error = 0 at the beginning of the code lo and behold it started saving to the db. Thx necafusu and RossMitchell, especially for that debug setting (useful) and yes I did reset it to false ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘save to db with wpdb’ is closed to new replies.