• I am trying to write a function that inserts pieces of data into my database.

    Here is what I have done so far:

    function insert_data($name, $email, $subject, $question){

    global $wpdb;

    $wpdb->query( $wpdb->prepare( “
    INSERT INTO $wpdb->[table_name]
    ( id, name, email, subject, questiom )
    VALUES ( %d, %s, %s, %s, %s )”,
    NULL, $name, $email, $subject, $question ) );

    }

    $name = “Joseph”;
    $email = “sample@sample.com”;
    $subject =”My Subject”;
    $question = “How are you?”;
    insert_data($name, $email, $subject, $question);

Viewing 1 replies (of 1 total)
  • If the actual code in use is what you posted above, I believe that the table name is not being interpreted properly:

    INSERT INTO $wpdb->[table_name]

    Did you use the actual table name in this code?

Viewing 1 replies (of 1 total)
  • The topic ‘Call to a member function query() on a non-object ( Help Guys! )’ is closed to new replies.