Title: wpdb syntax error?
Last modified: August 30, 2016

---

# wpdb syntax error?

 *  Resolved [aseliot](https://wordpress.org/support/users/aseliot/)
 * (@aseliot)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/wpdb-syntax-error/)
 * I get a syntax error on the insert query but I have no idea why.
 * The reason why I am trying to make a new table it a long story but there is no
   other way to solve my problem.
 * I’ve been at this for a while and the moment I enable the wpdb line it throws
   an error. But I think that the line is probably not the problem.
 *     ```
       global $wpdb;
           $charset_collate = $wpdb->get_charset_collate();
           $table_name = "vuora_mu_blog_id";
   
           $sql = "CREATE TABLE IF NOT EXISTS $table_name (
                 id mediumint(9) NOT NULL AUTO_INCREMENT,
                 blogname VARCHAR(50) NOT NULL,
                 blogid mediumint(9),
                 UNIQUE KEY id (id)
               ) $charset_collate;";
   
           require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
           dbDelta( $sql );
   
           $site_details = get_blog_details();
           $my_blogname = $site_details->blog_id;
           $my_blogid = $site_details->blogname;
   
           $wpdb->insert($table_name, array('blogname'=>$my_blogname, 'blogid'=>$my_blogid);
       ```
   

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

 *  [catacaustic](https://wordpress.org/support/users/catacaustic/)
 * (@catacaustic)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/wpdb-syntax-error/#post-6596584)
 * What is the actual error message that you’re seeing?
 *  Thread Starter [aseliot](https://wordpress.org/support/users/aseliot/)
 * (@aseliot)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/wpdb-syntax-error/#post-6596594)
 * I have an index file for a plugin the moment this is loaded I want to create 
   a new table and insert some data.
 * The error i got was a syntax error on the last line where I am trying to insert
   data into the table I just made. Making the table works fine but the insertion
   does not.
 * To test I just copied the code from this ([https://codex.wordpress.org/Creating_Tables_with_Plugins](https://codex.wordpress.org/Creating_Tables_with_Plugins))
   example into the page, but I as of now I can also not get the insertion working.
   The table is made but the data is not inserted for whatever reason (no error/
   notice and debugging is on).
 *  Thread Starter [aseliot](https://wordpress.org/support/users/aseliot/)
 * (@aseliot)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/wpdb-syntax-error/#post-6596600)
 * Woops i forgot a ) at the end of the line 🙁

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

The topic ‘wpdb syntax error?’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 2 participants
 * Last reply from: [aseliot](https://wordpress.org/support/users/aseliot/)
 * Last activity: [10 years, 8 months ago](https://wordpress.org/support/topic/wpdb-syntax-error/#post-6596600)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
