i have this function that i use to handle my errors
within php query and things like that
but i thought it will be better that if i can save the errors in the database then show it up in my admin control panel, so no one can see the errors that i have on my website
here is the function :
function er($str) {
global $db;
if (!$str) {
$errornum = $db->errorinfo();
echo $errornum[2];
die;
}
}
and here i was trying to do what i said i want to do :
function er($str) {
global $db;
if (!$str) {
$errornum = $db->errorinfo();
$en = $errornum[2];
echo "".$en."";
$db->query("INSERT INTO `error` (`con`) VALUES ('$en')");
die;
}
}
The Problem Is :
that the query dosent do anything
The Reason Is :
i believe that the reason is that $en is empty ... so the insert wont do anything as it dosent have a name to insert it into the database , but $en isnt empty as when i echo it i dose output the error .. i fugure that out while i was trying to get it work i replaced $en with (Example) and it worked and (Example) was there in the database
Fix :
I'm not sure but i think if i can get it to paste the real value of the $en .. then it will be working :D
But i need you to help me to do it or point me to the right direction
Well.
What you have to get rid of:
What you really have to do:
set proper error reporting for PHP. On a live server it have to be
error_reporting(E_ALL);
ini_set('display_errors',0);
ini_set('log_errors',1);
make your PDO throw exceptions as explained here: PDO query fails but I can't see any errors. How to get an error message from PDO?
this way you will see all your errors in cpanel and none of them will be spat to the user.
$db->query("INSERT INTO `error` (`con`) VALUES ('$en')");
instead try
$db->query("INSERT INTO `error` (`con`) VALUES ('".$en."') )";
If its echoing the error I doubt that $en is empty so its probably just a string interpolation issue.