Jump to content


Photo

custom function, mysql error reports- suggestions/bug holes...


  • Please log in to reply
3 replies to this topic

#1 leeming

leeming
  • Members
  • PipPipPip
  • Advanced Member
  • 93 posts

Posted 25 July 2006 - 01:50 PM

sorry if in wrong forum.. but it is kinda a help on fixing up this function i made, which replaces the "or die" after query errors, which relay on members of sites to report to you (if its just a die() message, or a mysql_error() message).
i will show the code here now, before i talk more about it....


edited, with line breaks as not to make it such a big scrolly text box
function reportError($note)  //note is used to identify, and short description of what the query is doing, and to locate it on my code *see update ideas*
{
    if($_SESSION[logname])//soon to be changed to an id, because of new site changes.. is the login name of user
    {
      $name = $_SESSION[logname];
    }
    else  //user is not a loged in user, pull ip instead
    {
      $name = getenv('REMOTE_ADDR');
    }
/* NOTE: 1 - see below for these notes */

  //insert into the database table, witht these my fields
  //- by: the $name *above* value
  //- report: out put report for admin to view
  //- type: this is a report system on my site, users can also report other things, eg non DB bugs, or other users...
  //-date: the ovious date & time of error
  mysql_query("insert into error (`by`, `report`, `type`, `date`) 
                     VALUES('$name',
                                'Page:".$_SERVER['SCRIPT_NAME']."<BR><b>".addslashes(mysql_error())."</b><BR>\'$note\'',
                               'Auto Report','".date("Y-m-d H:m:s")."')")

or die('<b>CRITICAL Function Error!!!</b>: Please <a href=report.php>report</a> this to an admin.');
  //report.php been the loged in page for members to report non DB errors *NOTE: 2*


//custom message for output from function, to let the user know there was an error, and it has been reported to the admin

  $message = "<b>ERROR</b>: There has been an error, but an error report has been sent and an admin will see to the problem as soon as posible
<BR>Sorry for any inconvenience, please <a href=\"/index.php\">click here</a> to go back to the site.";
  
  
  
  die($message);
}

NOTES:
1: See description of how reports look to admin *below*
2: Almost identical form, like members used to report, but for non loged in users (maybe its a log in bug or sign up?)



Report out puts..
shows reports to admin view only..
first thing it shows is, who it was reported by:
-if a member reported it, then their id is used to look up their name, and a link to an insite mail (and their member account profile)
-elseif a non loged in person (ip address), i have a code i found that vaidates ip addresses.. so it just shows the ip address. (doesnt show profile or mail link)

Type, is basicly the type of report (my function creates the type as "auto report")

Description, is normaly what the user inputs into a text area, but in this case, as an auto report shows description urm 'style' as  it is when the INSERT query runs.



now that i have explained how it works, and how its viewed (hopefully), i can continue on about imporvments im not too sure about (and any bug holes, i might have)

1. Removing $NOTE, as the function argument. and instead let it report the code line number (i tried this, but as my function is inside a functions include file. it shows the code line number for the query in that file (not where it was called from)

2. Very important failed DB queries, reported more directly to admin (email).

3. long shot / better way around... aswell as reported failed mysql queries, can be used with other error type messages (not syntax) like eg.
if($admin == 1)
{
 ...admin code
}
else
{
//curently like
  die('you should not be here');
 //but report these 'hack' attempts 
}
^or would it be better just to create another function for this
if not, use mysql errors, as the default for the function.

function reportError ($errorType = "sql")



that is basicly my custom built function... i hope to pick up any suggestions and/or help to patch it up (mainly for the mysql report part (the last suggestion was an extension.. not 2 needy).
And also if any one would like to use it ,if it seems like a good function to have (???)... (but maybe have a note/comment in your code, if you do want to use the code. That it was orginaly wrote by me "Leeming" and edited by you for what ever reasons (to fit your database reporting system??)

hope no one thinks its a stupid function, of if ive wasted my time, due to some thing thats way simple (??)
Im not perfect ;) lol

#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 25 July 2006 - 01:54 PM

If your using php 5 you'd be best to check out exceptions and custom exception handlers.

#3 leeming

leeming
  • Members
  • PipPipPip
  • Advanced Member
  • 93 posts

Posted 25 July 2006 - 02:36 PM

ok thanks, just looking them up now, might not understand them, but still gonna look them up...  one of them is "set_exception_handler" right?
Im not perfect ;) lol

#4 leeming

leeming
  • Members
  • PipPipPip
  • Advanced Member
  • 93 posts

Posted 25 July 2006 - 03:42 PM

If your using php 5 you'd be best to check out exceptions and custom exception handlers.


went into reading about it, but totaly forgot to check, php versionim running at.. (which sadly is PHP Version 4.4.1)

suggested fix for this, or continued support on the above function
Im not perfect ;) lol




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users