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

My code is

if( $wpdb->update($tableName,array('opt_value'=>$cInfo),array('opt_name'=>'showWeatherWidget')))
    //show success message
    // 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
up vote 7 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
    // 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

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.