#native_company# #native_desc#
#native_cta#

A Test To See If You Write Sloppy Software Page 4

By Tim Perdue
on March 10, 2003

Inside of functions, you should also handle all errors. The easiest thing to do is set a $feedback
variable, and in your header/footer template, you always echo out that $feedback variable if it
exists. This has worked well for me.

<?php

function my_function () {

    global 
$feedback;

    //code

    
if ($error) {

        
$feedback .= 'Could Not Perform Operation XXX';

        return 
false;

    } else {

        
$feedback .= 'Operation XXX Successfully Performed';

        return 
true;

    }

}

?>




Then you simply call these functions like this:

<?php

if (my_function()) {

    //do something

} else {

    //handle error

}

?>



Of course, the same error checks should be performed on database updates, inserts, and deletes.
Give yourself 1 point if you check all your database queries and provide proper feedback to the user.