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.

My code is

if( $wpdb->update($tableName,array('opt_value'=>$cInfo),array('opt_name'=>'showWeatherWidget')))
    //show success message
else
    // show failure message

This is not correct, $wpdb->update() returns false if it doesn't change any data, but there were no errors. Can someone tell me the proper way to display a success message that a field was updated?

share|improve this question
    
possible duplicate of Showing errors with $wpdb update –  kaiser Jul 24 '12 at 14:02
add comment

1 Answer

up vote 5 down vote accepted

The correct way is with === FALSE which differentiates from equalling zero, which is what a succesful query with no results returns.

if( $wpdb->update($tableName,array('opt_value'=>$cInfo),array('opt_name'=>'showWeatherWidget')) === FALSE)
    //show failure message
else
    // show success message
share|improve this answer
    
This conflicts with this answer, stackoverflow.com/questions/6529242/… which says : if ($result === false) // Fail -- the "===" operator compares type as well as value –  AlxVallejo Mar 15 '12 at 21:54
    
This is proven in my code - I vouch (and +1) this answer! Thanks JMC! –  Eric Holmes Dec 12 '12 at 15:06
add comment

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.