How to show mysql errors in a friendly manner and email error to admin

Started on the old forum in August 2011 · view the original in the archive · old links redirect here

#database #mysql-error

No replies · 685 views · started 15 years ago · 1 min read

razzbee Developer · 130 posts #1

This tutorials is meat to show you how you can show friendly errors to users nicely....

1.we creat a function

function c(){

$error_type=mysql_error();
$site_url=$_SERVER['HTTP_HOST'];
$site_url=str_replace("http://","",$site_url);
$page_name=$_SERVER['REQUEST_URI'];

$time=time();
$error_time=date('d-F-Y. h:m:sA',$time);
$from="error_messenger@$site_url";
 $to="your_email;
$subject="An error at $site_url";

$error_msg="Hi Admin,A database  error  ($error_type)  occured on the page http://$site_url$page_name  on the $error_time.<br>";

mail($to,$error_msg,$subject,$from);

exit("Database under maintenance ,please try again later.");

}

in this script U will have to change the email at the $to variable,..so this is how U will use the script

$query=mysql_query("SELECT * FROM tablename;")or die(mysql_error_msg());

so all db errors will be emailed to U and the errors too will be hidden

Write your reply now; next you create a free account (or sign in) and it is posted right away. Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close