• Well, I figured I’d give things a shot and attempt to create my first WordPress plugin. I’ve been successful in creating the Admin menus, creating a new Database table (when it doesn’t exist), and reading data from the Database.

    I am now attempting to add data to the database, but it seems no matter how many times I submit the data, nothing is added to the database.

    Here is the code that I’m using:

    $sql = "INSERT INTO " . $wpdb->prefix . "table_name
                      (table_row_name, table_row_2, table_row_3) VALUES (
                      '" . $wpdb->escape($_POST['table_row_name']) . "',
                      '" . $wpdb->escape($_POST['table_row_2']) . "',
                      '" . $wpdb->escape($_POST['table_row_3']) . "'
                      )";
            $wpdb->query($sql);

    As stated in the WordPress documentation about working with databases, I have included the following lines of code beforehand:

    include_once(ABSPATH . 'wp-config.php');
    include_once(ABSPATH . 'wp-includes/wp-db.php');

    I am definitely missing something here, but I am lost as to what. I’ve ensured that the SQL statement is complete with the values that are passed from the form (echoed the $sql variable on the “results” page). I don’t get any errors, but am completely lost as to what is going on. Any pointers?

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Data Not Inserted into Database upon submitting form’ is closed to new replies.