thereaper87 Posted December 24, 2010 Share Posted December 24, 2010 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! Quote Link to comment https://forums.phpfreaks.com/topic/222566-insert-query-in-die-message/ Share on other sites More sharing options...
mmarif4u Posted December 24, 2010 Share Posted December 24, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/222566-insert-query-in-die-message/#findComment-1151040 Share on other sites More sharing options...
thereaper87 Posted December 24, 2010 Author Share Posted December 24, 2010 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 Link to comment https://forums.phpfreaks.com/topic/222566-insert-query-in-die-message/#findComment-1151041 Share on other sites More sharing options...
mmarif4u Posted December 24, 2010 Share Posted December 24, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/222566-insert-query-in-die-message/#findComment-1151044 Share on other sites More sharing options...
thereaper87 Posted December 24, 2010 Author Share Posted December 24, 2010 Yep it makes perfect sense, thank you very much. Quote Link to comment https://forums.phpfreaks.com/topic/222566-insert-query-in-die-message/#findComment-1151046 Share on other sites More sharing options...
harristweed Posted December 24, 2010 Share Posted December 24, 2010 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 = "[email protected]"; 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"); Quote Link to comment https://forums.phpfreaks.com/topic/222566-insert-query-in-die-message/#findComment-1151047 Share on other sites More sharing options...
harristweed Posted December 24, 2010 Share Posted December 24, 2010 for $insert read $sql (doh! I just got up!!!) Quote Link to comment https://forums.phpfreaks.com/topic/222566-insert-query-in-die-message/#findComment-1151048 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.