Jump to content

Insert query in die message


thereaper87

Recommended Posts

Hello there,

 

I am trying to build my site more efficient by sending me error messages that occur. I have decided that most of my errors are mysql errors. Thinking about what to do, I tried to put an insert query in the die message. Here is my line of code below.

$globalsql=mysql_query("SELECT * FROM global") or die(' $error=mysql_query("INSERT INTO errors (name, identity, user,) VALUES ('"'Error 1'"', '"'global_functions.php'"', '"'System'"')") ');

However, I get this error:

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in global_functions.php on line 4

 

 

Which is that line. Any ideas?

 

Thanks!

Link to comment
Share on other sites

Well, the main purpose I would want this if there is an error that only occurs under certain conditions that I never seen. So that if there is an error, and I'm not that one that views it, it sends it to the error's table to be view easily and I can record what happened without actually it occurring to me.

Link to comment
Share on other sites

Well, the main purpose I would want this if there is an error that only occurs under certain conditions that I never seen. So that if there is an error, and I'm not that one that views it, it sends it to the error's table to be view easily and I can record what happened without actually it occurring to me.

Now thats more clear.

What you can do is prepare another if statement and check the query, if runs sucessfully skip the insertion part and if not inset the error and other stuff into a table, some thing like:

if(!$query) {
$sql = mysql_query("insert into table(....) values (...)");
}
else
{
}

 

Hope this make sense.

 

Link to comment
Share on other sites

What I do may give you some ideas, I have a function that send me an email...

function problem($message){
$today = date('Y-m-d H:i:s');
$mail_message =  $message;
$mail_message.="<br /><br />at: $today";
$subject = "Problem on [name of site] Website";    
$headers .= "From: info@[domain name]\n";
$headers .= "X-Priority: 2\n";
$headers .= "MIME-Version: 1.0\n"; 
$headers .= "Content-Type: text/html; charset=iso-8859-1\n";
$email = "me@mydomain.com";

if(mail($email, $subject, $mail_message, $headers));
    return;
} //end of email

 

then I have this in all mysql queries:

if(!mysql_query($sql)){
    $err=mysql_error();
    problem("page name.php - line number XX
    <br /><br />
    $err<br /><br />
    $insert");

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.