Quote:
Originally Posted by Custard7A
Firepages is right, logic like that is behind a lot of your problems. Consider your idea: You set up everything like it's an error, and only do the final outcomes depending on if it actually is. Hopefully, for the vast majority of times, your result will not be an error.
|
Not so.
I created a script called "results.php" to display a "result" or "outcome" message on the screen based on what a User did.
This includes "Error" messages like...
Quote:
Comment Not Found
The Comment you chose was not found.
Please try again. (2328)
<Return to Article>
|
And "Success" messages like...
Quote:
Comments Changed
Your article comments have been changed. (2330)
<Return to Article>
|
However, I will agree that the majority of my messages tend to deal more with when something goes wrong.
Quote:
|
You will not need an error set up in these cases, but you will still burdening your script with the assumption that it will be. Meaning this script could be running a lot smoother for pages not generating an error. You shouldn't need to assume anything in a good script.
|
Maybe part of the problem here is "What constitutes an 'Error'?"
To me, an "Error" is anytime the User doesn't get their expected outcome, or when the script fails.
Typically my scripts deal with the following "errors"...
- No Value (i.e. NULL) was passed
- No record can be found for the submitted Value
- The Value has an Invalid Format
- User is trying to do something that is not allowed
All of my "Error-Handling" is not dealing with Compile or Fatal Errors, and in fact, I'm not sure I know how to do that?!
What I am calling "Error-Handling" involves going through every branch of my code and making sure I have some "Results/Outcome" message for *every* scenario possible, so that my code *always* ends gracefully with some Custom Message.
If my code is invalid, then it wouldn't run, so I guess I catch "Compile" errors during testing?
And maybe I am being naive, but I guess I assume that by going through every branch in my code, combined with doing obvious things like checking for Nulls and checking for proper Data-Types, that my code has a branch - and message too - to handle everything that can happen.
Does that make sense?
(I was hoping that the code I posted before would give all of you a good idea of how my entire scripts look...)
Quote:
It should be this simple..
In a main file:
PHP Code:
if( !isset($_GET['section']) || strlen($_GET['section']) == 0) {
$_SESSION['Error'] = 2422; // Some error number, or something.
header("Location: ". BASE_URL ."/account/results.php"); }
In the results file:
PHP Code:
// Check if an error has been set.
if( isset($_SESSION['Error'])) && $_SESSION['Error'] != 0) {
switch($_SESSION['Error']){ // Find what error it is.
case 2422: echo "Error: No section defined in ". $_ENV['REQUEST_URI']; break;
// Add new cases for any self-defined error you may use.
default: echo "No error was defined."; break;
} }
|
But that is almost identical to what I have?!
Quote:
|
1 ). You wouldn't echo the message like that, that's just for simple example. If it was me I would call a function there that would then handle logging and emailing. Well, if it was me I wouldn't be doing anything like this, lol.
|
Then what would you do??
Quote:
|
4 ). You are doing a lot of writing and asking a lot of questions. This isn't necessarily bad, but you're making it hard for anyone to help you. If you are serious about fixing your problems you should consider taking some of the previous advice to heart, and going to the PHP documentation or Google and doing a bit of reading. A little more effort to understand what is being suggested could go a long way, and save you more time in the end.
|
And I said I didn't understand what was suggested above, so RE-reading the PHP Manual won't do a whole lot of good...
Debbie