Title: Can&#039;t insert into WordPress DB
Last modified: August 19, 2016

---

# Can't insert into WordPress DB

 *  [foo_bar](https://wordpress.org/support/users/foo_bar/)
 * (@foo_bar)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/cant-insert-into-wordpress-db/)
 * I’m having some trouble inserting data in to a table that I’ve created. Is there
   anything wrong with this code? None of them works.
 *     ```
       $wpdb->query(
       			$wpdb->prepare('INSERT INTO gowestgallery
       				(main_url, thumbnail_url, title, text) values (%s, %s, %s, %s)',
       				$main_url, $thumbnail_url, $title, $text
       			)
       		);
   
       		$wpdb->insert('gowestgallery', array(
       			'main_url' => $main_url,
       			'thumbnail_url' => $thumbnail_url,
       			'title' => $title,
       			'text' => $text
       			), array( '%s', '%s', '%s', '%s', ));
       	*/
   
       		// Insert the post into the database
       		wp_insert_post(array(
       			'main_url' => $main_url,
       			'thumbnail_url' => $thumbnail_url,
       			'title' => $title,
       			'text' => $text
       		));
       ```
   

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

 *  Anonymous User
 * (@anonymized-3085)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/cant-insert-into-wordpress-db/#post-1743618)
 * aren’t you missing the $wpdb->prefix from the table names?
 *  Thread Starter [foo_bar](https://wordpress.org/support/users/foo_bar/)
 * (@foo_bar)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/cant-insert-into-wordpress-db/#post-1743622)
 * I created the table myself, so it doesn’t have the wp_ prefix.
 * Or should i write something like
    `INSERT INTO $wpdb->gowestgallery` ?
 * Thanks
 *  Anonymous User
 * (@anonymized-3085)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/cant-insert-into-wordpress-db/#post-1743638)
 * review:
    [http://codex.wordpress.org/Function_Reference/wpdb_Class](http://codex.wordpress.org/Function_Reference/wpdb_Class)

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

The topic ‘Can't insert into WordPress DB’ is closed to new replies.

 * 3 replies
 * 2 participants
 * Last reply from: Anonymous User
 * Last activity: [15 years, 7 months ago](https://wordpress.org/support/topic/cant-insert-into-wordpress-db/#post-1743638)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
