What is wrong with this wpdb update?

I’ve read a lot of documentation tonight, can’t see why this isn’t working. Obviously something I’m missing.

$newstr = "18,19";
$defid = 1;
$table = "wp_tablename";
$data = "array( 'somecol' => '".$newstr."' )";
$where = "array( 'id' => ".$defid." )";

if ($wpdb->update( $table, $data, $where) === FALSE)
{
    echo "failure";
}
else
{
    echo "success";
}

Comes up false every time. Any clues? What am i missing here? I did try using format_where and that didn’t work either.

Related posts

Leave a Reply

2 comments

  1. you’re creating the $data and $where values as strings, not arrays.

    this:

    $data = "array( 'somecol' => '".$newstr."' )";
    $where = "array( 'id' => ".$defid." )";
    

    should be:

    $data = array( 'somecol' => $newstr );
    $where = array( 'id' => $defid );