• I am working on making a WordPress version of a contact form submit script that I wrote in plain PHP a while back. I am having a ton of trouble trying to figure out how to get a workable MySQL query going.

    -I already set up the table through phpMyAdmin and made sure my table had the standard wp_ prefix, so I know it is not the problem.

    -Here is my database include (I made it a require so it would error out if I didn’t do something right):
    require('../../../wp-includes/wp-db.php');

    Here is my query script. It is written pretty much in accordance with http://codex.wordpress.org/Class_Reference/wpdb:

    $wpdb->query( "INSERT INTO $wpdb->NEW_CONTACTS (SUBMIT_DATE, FIRST_NAME, LAST_NAME, EMAIL, PHONE_NUMBER, COMMENTS)
    VALUES ('$date','$firstName','$lastName','$email','$phone','$comments')" );

    When I try executing the script, I get this error message which directly corresponds to my query line:
    Fatal error: Call to a member function query() on a non-object in /home/content/17/7848217/html/wordpress/wp-content/plugins/submitForm/index.php on line 44

    If anybody can give a second pair of eyes to this, I would greatly appreciate it. FYI, I am only interested in using the $wpdb->query method, not the $wpdb->insert one. Also, the MySQL escapes will come after I figure out the problem with the query.

Viewing 1 replies (of 1 total)
  • The problem may be that NEW_CONTACTS is not a registered table with WP so that $wpdb->NEW_CONTACTS returns nothing.

    Try your query with a hard-coded table name:

    $wpdb->query( "INSERT INTO wp_NEW_CONTACTS (SUBMIT_DATE, FIRST_NAME, LAST_NAME, EMAIL, PHONE_NUMBER, COMMENTS)
    VALUES ('$date','$firstName','$lastName','$email','$phone','$comments')" );
Viewing 1 replies (of 1 total)
  • The topic ‘Can't figure out MySQL query for contact form’ is closed to new replies.