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
https://forums.phpfreaks.com/topic/222566-insert-query-in-die-message/
Share on other sites

Whats the purpose of putting a query in die statement?.

There are pre defined error messages for mysql to output, why not use them?, like mysql_error, mysql_errno etc etc.

OR even you can write your own error message to output.

 

http://php.net/manual/en/function.mysql-error.php

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.

  Quote

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.

 

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");

 

Archived

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

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