context
I have been working on a new wordpress blog as a personal website. Part of it, I have a custom contact form where people put in their details to get in touch with me.It has been working good till morning, after which I have updated to 4.2.2v citing security reasons.
problem
After the update, the form is failing to save any of the information into the DB. The $wpdb->insert_id
is returning 0. The query is the same, the page is the same, everything is just the same. The only change is I have upgraded to 4.2.2v from 4.2.1v.
Is there any issue with the recent update or do I have to do any more steps after the word press manual update ?
debugging done…
I have ensured that the DB version is updated. It is showing 31535. When debugging using the $wpdb->lastquery
and $wpdb->print_error()
I get
WordPress database error: []
SHOW FULL COLUMNS FROM `wp_tst_tbl_contacts`
?
I could not understand what is wrong here. If I run the same insert query, as well as the above show full columns
on command line using the same user wp user credentials, it works perfectly.
note: If there is anymore information needed, please ask.
I found the problem cause. Its due to a column width limitation.
I have a VARCHAR(9) column and I was sending data that is 16 char length. The new change in the 4.2.2 gets the table meta and crops the data such that it fits properly into the size of the column as defined in DB. And it also compares the pre-crop and post-crop data. If they don’t match, it is failing.
The problem is, its failing silently with no error thrown. I have found this via debugging the wpincludes/wp-db.php file.
Please check your column limit and the column data length you send.
Once I have increased the column width (as the data will definitely be more than 9 chars), the issue got resolved.
I was experiencing this same issue and it turned out to be some unescaped values being pushed into the database from a csv import function.
I applied the proper
esc_url()
and / oresc_attr()
and / oresc_html()
where appropriate to sanitize the values pre-insertion and then the query ran successfully.