Support » Plugins » Store form data in new table in WordPress database

  • I need to create a form that, when submitted, stores the form data in the WordPress database. I can create the functions to do this in the standard PHP/MySQL integration way, but I want to not have to re-enter the DBHost, Username, and Password. I understand that using $wpdb may be a good way to use the standard WordPress installation host, username, and password to communicate with the database. I tried several variations of this with no luck. I also need to be able to do this from a template file. Can anyone help with this?

    In short what I need is

    • WP to check if a certain database table of my naming exists
    • To create it if it does not exist
    • To store all form data in that database table every time the form is submitted
    • To retrieve that data through a separate template file
    • All using the information from the wp-config.php file without reentering it

      I know that is a lot, but if anyone can help I would greatly appreciate it. Thank you!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Michael Torbert


    WordPress Virtuoso

    Just use $wpdb.
    It’s exactly the same as a normal MySQL query using PHP only you’re using the wpdb class for some PHP variables. Just output your query string which uses wpdb. If it looks like a normal MySQL query that would work, then it will work with the wpdb.

    I have read and re-read, tried and tried again the instructions in the wpdb codex page. I could just be missing something. Any chance you could give example code of how it should work to do what I specified? I know it should work, but I can’t seem to get it to. Also, is something extra required when creating the table with $wpdb? I think the problem may be with creating it. Thank you for any help you may be able to give!

    I need to create something similar to fragmentist.

    I’m surprised there’s no plugin available for this, or at least not that any of my searching has revealed. Although to be hones I’d rather write everything myself in order to learn.

    Someone must have a link to a well written tutorial on the subject?

    Michael Torbert


    WordPress Virtuoso

    It works just like a normal SQL query would work, only the query string you actually write is using PHP variables. Echo the string and ensure it looks the way it would if you weren’t using wpdb.

    The instructions for wpdb in the codex are very long and detailed and give numerous examples. Feel free to look at my SMS Text Message plugin for another example.

    At some point in time I may be interested in writing a plugin that has this functionality.

    I started a forum topic outlining what I would like to see in a plugin that does this.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Store form data in new table in WordPress database’ is closed to new replies.