Title: Problem using wpdb
Last modified: August 20, 2016

---

# Problem using wpdb

 *  [singhal_pooja_j](https://wordpress.org/support/users/singhal_pooja_j/)
 * (@singhal_pooja_j)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/problem-using-wpdb/)
 * Hi,
    I want to create a table using wpdb and dbDelta. The code is as follows.
   But the table is not getting created and I’m also not getting any error message.
 * $sql = “create table $table_name (
    club_id int(11) NOT NULL auto_increment, 
   project_name varchar(500) NOT NULL, first_name varchar(100) NOT NULL, school_status
   varchar(50) NOT NULL, school_name varchar(200) NOT NULL, school_city varchar(
   50) NOT NULL, school_state varchar(50) NOT NULL, year_in_school varchar(50) NOT
   NULL, age int(2) NOT NULL, email varchar(200) NOT NULL, mobile varchar(15) NOT
   NULL, chat_id varchar(50) NOT NULL, facebook_page_link varchar(200) NOT NULL,
   mailing_address_street varchar(50) NOT NULL, mailing_address_city varchar(50)
   NOT NULL, mailing_address_state varchar(50) NOT NULL, mailing_address_zip char(
   6) NOT NULL, social_networking varchar(50) NOT NULL, organization_involvement
   varchar(2000) NOT NULL, club_heard varchar(50) NOT NULL, volunteer_experience
   varchar(2000) NOT NULL, volunteer_reason varchar(2000) NOT NULL, skills varchar(
   2000) NOT NULL, creative_ideas varchar(5000) NOT NULL, other_information varchar(
   2000) NOT NULL, face_photo_url varchar(200), school_image_url varchar(200), video_clip_url
   varchar(200), PRIMARY KEY (club_id) );”;
 * require_once(ABSPATH . ‘wp-admin/includes/upgrade.php’);
    dbDelta($sql);
 * Can you guys please help?
    Thanks a lot in advance.

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

 *  [s_ha_dum](https://wordpress.org/support/users/apljdi/)
 * (@apljdi)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/problem-using-wpdb/#post-2933860)
 * dbDelta is really picky.
    -  You have to put each field on its own line in your SQL statement.
    -  You have to have two spaces between the words PRIMARY KEY and the definition
      of your primary key.
    -  You must use the key word KEY rather than its synonym INDEX and you must 
      include at least one KEY.
    -  You must not use any apostrophe around field’s name. (otherwise dbDelta will
      encounter a bug during preg_match)
 * [http://codex.wordpress.org/Creating_Tables_with_Plugins#Creating_or_Updating_the_Table](http://codex.wordpress.org/Creating_Tables_with_Plugins#Creating_or_Updating_the_Table)
 * If you have MySQL less that 5.0.3 you may have trouble with those varchar definitions.
 * > Values in VARCHAR columns are variable-length strings. The length can be specified
   > as a value from 0 to 255 before MySQL 5.0.3, and 0 to 65,535 in 5.0.3 and later
   > versions….
   > [http://dev.mysql.com/doc/refman/5.0/en/char.html](http://dev.mysql.com/doc/refman/5.0/en/char.html)
 * I don’t know if that is a factor. Maybe dbDelta doesn’t like it even if the database
   would accept it.
 * Nothing really stands out though…
 *  Thread Starter [singhal_pooja_j](https://wordpress.org/support/users/singhal_pooja_j/)
 * (@singhal_pooja_j)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/problem-using-wpdb/#post-2933931)
 * Thanks s_ha_dum for the reply.
    I have taken of all the rules to be followed 
   when using dbDelta. Also I’m using MySQL5.0.95. I’m able to create the table 
   using phpMyAdmin but not through plugin code.
 *  [s_ha_dum](https://wordpress.org/support/users/apljdi/)
 * (@apljdi)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/problem-using-wpdb/#post-2933933)
 * I have had mysterious trouble with dbDelta in the past. There are things I never
   worked out. It is a frustrating function.

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

The topic ‘Problem using wpdb’ is closed to new replies.

## Tags

 * [dbDelta()](https://wordpress.org/support/topic-tag/dbdelta/)
 * [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: [s_ha_dum](https://wordpress.org/support/users/apljdi/)
 * Last activity: [13 years, 10 months ago](https://wordpress.org/support/topic/problem-using-wpdb/#post-2933933)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
