WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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";
    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.

share|improve this question

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


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

should be:

$data = array( 'somecol' => $newstr );
$where = array( 'id' => $defid );
share|improve this answer
LoL. Yep sure am. That's probably it. Thanks! It's been a long day. ;) – michael Feb 16 '13 at 5:44
Well that didn't fix it after all. when fixing those two lines it still fails. – michael Feb 16 '13 at 7:17

Don't use 'identical' operator ===, use simply if ($wpdb->update(.......) {.......} because a boolean value is passed on to a control structure. See PHP Comparison Operators. See Milo's answer for strings and arrays.

share|improve this answer
Thanks, I did get it working. All was well when i used format and format_where in wpdb->update. I guess the first time i used it I had the formats wrong so it wasn't finding the row to update. Thanks to Milo for pointing out the string issue. All is good now. – michael Feb 16 '13 at 22:47

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.