Title: $wpdb-&gt;insert does nothing when creating a table programmatically
Last modified: August 30, 2016

---

# $wpdb->insert does nothing when creating a table programmatically

 *  Resolved [mjd82](https://wordpress.org/support/users/mjd82/)
 * (@mjd82)
 * [11 years ago](https://wordpress.org/support/topic/wpdb-insert-does-nothing-when-creating-a-table-programmatically/)
 * I am creating a custom table in the WP database. However, after this is created
   successfully I don’t seem to be able to actually insert a row into it… Am I missing
   something here?
 *     ```
       // store the specified img URL in the wp db
       if (!empty($_POST['imgURL'])) {
         global $wpdb;
         $table_name = $wpdb->prefix . 'my_custom_table';
   
         if ($wpdb->get_var('SHOW TABLES LIKE "' . $table_name . '"') === $table_name) {
           $delete = $wpdb->query('TRUNCATE TABLE ' . $table_name);
         } else {
           require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
           $charset_collate = $wpdb->get_charset_collate();
           $create = "CREATE TABLE $table_name (
             url varchar(55) NOT NULL DEFAULT ''
           ) $charset_collate;";
           dbDelta($create);
         }
   
         $wpdb->insert($table_name, array('url' => $_POST['imgURL']));    // why doesn't this work???
         wp_send_json_success(array('msg' => 'Image inserted in database successfully'));
       }
       ```
   

Viewing 1 replies (of 1 total)

 *  Thread Starter [mjd82](https://wordpress.org/support/users/mjd82/)
 * (@mjd82)
 * [11 years ago](https://wordpress.org/support/topic/wpdb-insert-does-nothing-when-creating-a-table-programmatically/#post-6230665)
 * Increasing the varchar() did the trick in the end.

Viewing 1 replies (of 1 total)

The topic ‘$wpdb->insert does nothing when creating a table programmatically’ is
closed to new replies.

## Tags

 * [ajax](https://wordpress.org/support/topic-tag/ajax/)
 * [wpdb](https://wordpress.org/support/topic-tag/wpdb/)

 * 1 reply
 * 1 participant
 * Last reply from: [mjd82](https://wordpress.org/support/users/mjd82/)
 * Last activity: [11 years ago](https://wordpress.org/support/topic/wpdb-insert-does-nothing-when-creating-a-table-programmatically/#post-6230665)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
