Title: Mysql insert not saving
Last modified: December 30, 2016

---

# Mysql insert not saving

 *  Resolved [Jassop](https://wordpress.org/support/users/jassop/)
 * (@jassop)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/mysql-insert-not-saving/)
 * Hi,
 * I am having trouble saving a row to the DB. I have a plugin that i have modified
   slightly (added one extra column in the DB table). When it saves to the DB, the
   query returns successfully and has a value of the ID (auto-incremented in MySQL),
   but the row does not get saved. The code is fairly vanilla:
 *     ```
       $query = $wpdb->prepare($query, $values);
       $query_results = $wpdb->query($query);
       if($query_results) {
         return $wpdb->insert_id;
       }
       ```
   
 * So this works for two other calls in the same form action, `$wpdb->insert_id`
   contains the next valid auto-id, but no rows are in the DB. I have tried turning
   on all the logging I can, and there are no errors at all. `$wpdb->show_errors();`
   has no content.
 * Also the SQL seems to be OK – I can use the text from `$query` or `$wpdb->last_query`
   in a DB window and they work fine, and insert a row that I can see.
 * I was guessing there was a transaction on that table, so copied the DB to a new
   one and reran, but had the same results.
 * I am not sure how to debug this further. I don’t have access to the error logs
   in the DB itself as it is on a shared host.
 * The server is MySql 5.6.34, PHP 5.6.28.
 * If anyone has any ideas or tips on moving forward, please let me know.
 * Thanks!

Viewing 1 replies (of 1 total)

 *  [Justin Greer](https://wordpress.org/support/users/justingreerbbi/)
 * (@justingreerbbi)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/mysql-insert-not-saving/#post-8602471)
 * Could you provide more details about your query. If `$wpdb` is returning a `insert_id`
   then the query is working and a row has been inserted as you mentioned. The insert_id
   is not something that the db object generates so we know it is working.
 * Be sure to also set `WP_DEBUG` to `true` as well in order to see the query error(
   if any). You say that `insert_id` is being returned so the show_errors will not
   be helpful.

Viewing 1 replies (of 1 total)

The topic ‘Mysql insert not saving’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [Justin Greer](https://wordpress.org/support/users/justingreerbbi/)
 * Last activity: [9 years, 5 months ago](https://wordpress.org/support/topic/mysql-insert-not-saving/#post-8602471)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
