• Resolved gusqc

    (@gusqc)


    Hi,

    First time writing a plugin for WordPress. I am trying to insert data into wp_wptest, a table I created in the database. The below code inserts 12 rows in the database instead of one. The string “INSERT” only prints once in the page source. I only want to insert one row in the db. Here is the code:

    echo "INSERT" . "<br />";
    
    $this->m_pathlogo = "AAAAA.gif";
    $this->m_customerid = 1;
    
    $dbfields["customerid"] = $this->m_customerid;
    $dbfields["pathlogo"] = $this->m_pathlogo;
    $dbfields["date"] = "now()";
    
    $wpdb->insert( 'wp_wptest', $dbfields);

    Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • You code would look to be correct…so just a few things to try:

    Put this before your insert statement to see if it tells you anything:

    echo "<pre>"; print_r($dbfields); echo "</pre>";

    Change the insert statement to

    $result = $wpdb->insert( 'wp_wptest', $dbfields);

    Also, this after the insert to see if the return shows anything

    echo "<pre>"; print_r($result); echo "</pre>";

    Thread Starter gusqc

    (@gusqc)

    Thanks alot, it fixed the issue!

    SO I guess this fixed it?

    $result = $wpdb->insert( 'wp_wptest', $dbfields);

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘$wpdb->insert issue’ is closed to new replies.