WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am looking for something really simple(?). I am using WordPress as a CMS. I created a new page in which I added a form (questionnaire). Inside WordPress' database (the same database in which all WordPress data are), I created a new table called "ExampleTable".

Now I have 2 questions:

1) How can I insert data from the form into that custom table? 2) Is is "okay" to add a custom table (which has nothing to do with WP inside WordPress' database, or should I create a new database?)

Thanks :)

share|improve this question
up vote 0 down vote accepted

It is OK. And you can access this table with standard way, throught wpdb

To insert data to your table use this code:

global $wpdb;
        'column1' => 'value1', 
        'column2' => 123 

To breafly explain what this code mean. WordPress sanitizes values before inserting them into database (to prevent database being compromited by SQL injection.). First line defines table to inser value. Secon array contains col names and value being inserted. The third array contains type of value to insers. %s stands for string, %d stands for int (digit).

You can read more about $wpdb->prepare in the codex. It is well explained in there.

share|improve this answer
Hey thanks for the answer. Sorry, I am a real beginner. Could you please explaine what %s and %d stands for; and why I need to specify it? – Kaneda Jan 31 '13 at 20:13
I've updated the answer. But have a look to the codex, everything is well explained in there: codex.wordpress.org/Class_Reference/wpdb – david.binda Jan 31 '13 at 20:42
Thanks for the fast and supportive comment :) – Kaneda Jan 31 '13 at 21:11

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.