Quote:
Originally Posted by firepages
Fou-Lu's suggestion is by far really the best way to go though perhaps its too late in V2 to start rewriting, thats your call.
|
Well, first I need to understand what he is recommending. (The built-in error-handling he mentioned has always been Greek to me, which is probably why I created what I have now?!)
Quote:
Originally Posted by firepages
for your existing code I can't see why you would get an email if there were was no error ... unless...
PHP Code:
<?php
$_SESSION['resultsCode'] = 'ARTICLE_INDEX_NO_QUERY_STRING_2422';
?>
when its an error it should be e.g.
<?php
$_SESSION['errorCode'] = 'ARTICLE_INDEX_NO_QUERY_STRING_2422';
?>
|
Precisely!!!
The *main reason* I want to re-write my Error-Handling, is because as it stands now, the Admin (i.e. ME) gets an e-mail every time there is an outcome!
Add a Friend? (I get an e-mail?!)
Post a Comment below an Article? (I get an e-mail?!)
I *always* want to log "Failures" and "Successes" in my database - if I take the time to write the code for it.
However, e-mails should only go out to the Admin when there is an Error, and so some action is probably need.
---------
Below is some more code that will hopefully better illustrate my current code-base...
"add_comment.php"
PHP Code:
// Verify Insert.
if (mysqli_stmt_affected_rows($stmt3)==1){
// Insert Succeeded.
$_SESSION['resultsCode'] = 'COMMENT_MEMBER_COMMENT_ADDED_2052';
// Set values for Success Message.
$_SESSION['firstName'] = $firstName;
$_SESSION['heading'] = $heading;
// Notify Other Subscribed Members
notifySubscribersOfNewComment($dbc, $articleID, $commentID, $sessMemberID);
}else{
// Insert Failed.
$_SESSION['resultsCode'] = 'COMMENT_MEMBER_COMMENT_FAILED_2053';
}// End of VERIFY INSERT.
// Set Error Source.
$_SESSION['errorPage'] = $_SERVER['SCRIPT_NAME'];
// Redirect to Display Outcome.
header("Location: " . BASE_URL . "/account/results.php");
// End script.
exit();
(**Notice, too, that I have other random variables that I like to pass to my Error/Success Messages?! Currently, I always pass $_SESSION['resultsCode'] and $_SESSION['errorPage'], but it not uncommon for me to pass something off-the-wall to make the message more meaningful and personal.)
"results.php"
PHP Code:
// Comment Added.
case 'COMMENT_MEMBER_COMMENT_ADDED_2052':
echo '<h1>Comment Submitted</h1>';
echo '<p>Thanks, '
. str2htmlentities($firstName)
. ', for sharing your thoughts! (2052)</p>';
echo '<p>Once approved, your comment will appear below the article:<br />
<span id="heading">' . '"'
. str2htmlentities($heading)
. '"</span></p><br />';
echo '<ul>
<li>
<a class="button2" href="' . BASE_URL . $returnToPage . '">Return to Article</a>
</li>
<li>or</li>
<li>
<a class="button2" href="' . BASE_URL . '/">Go to Home Page</a>
</li>
</ul>';
break;
// Comment Not Added.
case 'COMMENT_MEMBER_COMMENT_FAILED_2053':
echo '<h1>Comment Failed</h1>';
echo '<p>Your comment could not be added due to a system error.</p>';
echo '<p>Please contact the System Administrator. (2053)</p>';
echo '<a class="button" href="' . BASE_URL . $returnToPage . '">Return to Article</a>';
break;
(Of course, there is quite a bit more code in "results.php", but the code above shows you the "Error/Success Message" I display on the User's screen...)
Quote:
Originally Posted by firepages
I sounds like you issue an email for every resultsCode when you should probably do a check at that stage of your logic for resultsCode AND errorCode and act accordingly
|
That is the gist of it, however I am trying to find the easiest way to tweak my existing code base for v2.0 (When I hopefully go to OOP in v3.0, I can tackle this entirely differently if it makes sense.)
Right now, I estimate my website is maybe 30 scripts, 15,000 lines of code, and "results.php" is about 2,100 lines of code, with 1,600 of those lines being *customized* Error/Success Messages that I don't want to touch except for what we are talking about related to Screen Messages and E-mail Content.
Hope that helps better explain what I am trying to tackle?!
Sincerely,
Debbie