A couple of things.
1) Delay your output to the very end. That way you can still do page
redirects and build whole new pages depending on the errors you get.
2) Store errors in the session, then when building the page have a place
for put any error messages here, then delete them from the session.
3) Better yet, use PHP's set_error_handler() features to break out of the flow
of the page completely when necessary. You can do a lot more error checking
that way, and it makes the code cleaner to boot.
4) Structure your code so that you can't send malformed SQL in the first
place. :-) If you're writing a static query, test it before it goes live
(duh). If it's a dynamic query, structure it in such a way that it can't not
be valid. (There's lots of ways do to that. I find arrays and implode() to
work well for me.) At worst you'll return an empty result set, which is not
an error but in fact a genuine situation you should be accounting for anyway.
What you're doing below is really just a fancy version of mysql_query() or
die, which I've always felt is very sloppy code.
On Sunday 18 June 2006 10:33, Beauford wrote:
Hi,
If I were to have something like the following, what is the best way (or
best practice) to reload the page and display the error - or is there a
better way to do this. I want to keep the site uniform and don't want
errors popping up and making a mess.
Thanks
B
-
$query = select idn, name from manager order by name;
$results = mysql_query($query) or $mysqlerror = mysql_error();
if ($mysqlerror) {
$error = $table_error$mysqlerror;
include(season.php); - This is not what I really want and
in some cases
it cause problems.
exit;
}
else {
The rest of the code
}
--
Larry Garfield AIM: LOLG42
[EMAIL PROTECTED] ICQ: 6817012
If nature has made any one thing less susceptible than all others of
exclusive property, it is the action of the thinking power called an idea,
which an individual may exclusively possess as long as he keeps it to
himself; but the moment it is divulged, it forces itself into the possession
of every one, and the receiver cannot dispossess himself of it. -- Thomas
Jefferson
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php