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.
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.
Give yourself 1 point if you check all your database queries and provide proper feedback to the user.