Jump to content


This topic is now archived and is closed to further replies.


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

Recommended Posts

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....

[i]edited, with line breaks as not to make it such a big scrolly text box[/i]
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`)
                              '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.";

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?)[/quote]

[u]Report out puts..[/u]
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
//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.

[code]function reportError ($errorType = "sql")[/code]

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 (??)

Share this post

Link to post
Share on other sites
If your using php 5 you'd be best to check out exceptions and custom exception handlers.

Share this post

Link to post
Share on other sites
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?

Share this post

Link to post
Share on other sites
[quote author=thorpe link=topic=101797.msg403160#msg403160 date=1153835690]
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

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.