Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

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 );
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

 
discard

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.