1

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.

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 );
2
  • 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
0

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.

1
  • 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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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