1

enter image description here I am writing a query for inserting data in to database but when I am printing query at output it turns into "SHOW COLUMNS from tbl_name" query. I am writing below query . But it executes like shown in image

$table_name1 = $wpdb->prefix . 'fullcontact';
    $sql1=$wpdb->insert( $table_name1, array(
        'status' => $status,
        'request_id' => $req_id,
        'likelihood' => $likelihood,
        'photos' => $photos,
        'chats' => $chats,
        'websites' => $websites,
        'fullname' => $fullname,
        'familyname' => $familyname,
        'givenname' => $givenname,
        'organisation' => $organisation,
        'normalizedlocation' => $normalizedlocation,
        'city' => $city,
        'state' => $state,
        'country' => $country,
        'age' => $age,
        'agerange' => $agerange,
        'gender' => $gender,
        'locationgeneral' => $locationgeneral,
        'socialprofiles' => $socialprofiles,
        'scores' => $scores,
        'topics' => $topics
    ) );

    //exit( var_dump( $wpdb->last_query ) );
    $wpdb->show_errors();
    $wpdb->print_error($sql1);
5
  • 1
    Please elaborate on "printing query". What exactly are you doing and in what order?
    – Rarst
    Jun 6 '17 at 7:55
  • $table_name1 = $wpdb->prefix . 'fullcontact'; $sql1=$wpdb->insert( $table_name1, array( 'status' => $status, 'request_id' => $req_id, 'likelihood' => $likelihood ) ); $wpdb->show_errors(); $wpdb->print_error($sql1);
    – compoholic
    Jun 6 '17 at 8:56
  • i am printing this query by show_error() and print_error() function
    – compoholic
    Jun 6 '17 at 8:56
  • I don't quite follow what you are trying to do there. Why explicit print_error() with result of your query?
    – Rarst
    Jun 6 '17 at 9:05
  • can I mail you the pics plz ? I am hard stuck at this..it wud be kind if you help me.
    – compoholic
    Jun 6 '17 at 9:10
2

For anyone else finding this question. Wordpress seems to do a SHOW FULL COLUMNS query before executing the INSERT query. If it determines that the INSERT query would fail/store bad data, for example because the given data types would not fit in the column, it does not execute the insert query at all and return false.

Check:

  • Have you filled all fields that can not be null and do not have a default value
  • Does the data type for every field match the data type in the database
  • Does the data passed to the function violate any constraints? A string cannot be longer than the maximum length of the field you are trying to put it into. An integer field has a minimum and maximum value. Unsigned integers cannot contain negative values.
1
  • Exactly.. I had did this in past and it worked..!
    – compoholic
    Jul 20 '17 at 12:48
0

Just had the same Problem, the fix was i tried to add varchar longer than the database field can hold. When changed the DB it workled again

1
  • thank You but it did'nt worked for me..anything else please ?
    – compoholic
    Jun 6 '17 at 11:08

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.