4

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?

9

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
  • 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 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.