• This kind of works, my variables get wiped in the DB though, not updated. Please help!

    global $wpdb;
    
    		if( !function_exists('get_option') )
    		{
    			require_once('wp-config.php');
    		}
    $wpdb->update("mytable",  array('mycol1' => $_REQUEST["v1"],
    'mycol2' => $_REQUEST["v2"],
    'mycol3' => $_REQUEST["v3"] ),
    array('qsId' => $_REQUEST["customer_id"] ));

    So is the second array where I specify the ID of the table row to update?

Viewing 3 replies - 1 through 3 (of 3 total)
  • A good walkthrough on interacting with the WordPress DB can be found here:
    https://wp.smashingmagazine.com/2011/09/21/interacting-with-the-wordpress-database/

    This is the format the update helper expects.
    $wpdb->update( $table, $data, $where, $format = null, $where_format = null );

    Also, if the value in your db table is getting wiped, are you sure your variables are actually set?

    Thread Starter phillbooth

    (@phillbooth)

    Perhaps Im having a bad day but I just cant seem to gee the update to work, everything else does $wpdb->query. $wpdb->insert etc

    $wpdb->update('questions', array( 'qsEasyContact' => $myvar), array('qsId' => $_REQUEST["customer_id"]), array("%s"), array("%d") );

    Thread Starter phillbooth

    (@phillbooth)

    Worked it out…

    $wpdb->update('questions', array( 'qsEasyContact' => $myvar),"WHERE qsId =".$_REQUEST["customer_id"]);

    thx anyhow

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How do you update a custom table using wp functions’ is closed to new replies.