Auto php email if mysql error

Getting cold here so I’m working on a fun little php project.

I’m trying to get an email sent if there is a problem in a mysql_query. The following code sends an auto email ok but it doesn’t send the actual mysql error.


$to_error = "name@hotmail.com";
$subj_error = "Database Table Update Report";
$mssg_error = "Database ERROR: ". mysql_error()."\
\
";
$hdrs_error = "From: Error In Feed\
";

mysql_query("OPTIMIZE TABLE table_name") or die(mail($to_error, $subj_error, $mssg_error, $hdrs_error));

Any ideas out there?

thanks

when this line

$mssg_error = "Database ERROR: ". mysql_errorCOLOR=#007700."

"
;[/COLOR]

is run, mysql_error() won’t have a value.

you need to add the output from mysql_errorCOLOR=#007700 after the query is run.[/COLOR]

[COLOR=#007700]


[COLOR=#007700][COLOR=#007700][COLOR=#007700][COLOR=black]<?php[/COLOR][/COLOR][/COLOR]
[COLOR=#007700][COLOR=#007700][COLOR=black]$to_error = "[/COLOR][EMAIL="name@hotmail.com"][COLOR=black]name@hotmail.com[/COLOR][/EMAIL][COLOR=black]";[/COLOR]
[COLOR=black]$subj_error = "Database Table Update Report";[/COLOR]
[COLOR=black]$hdrs_error = "From: Error In Feed\
";[/COLOR][/COLOR][/COLOR]
 
[COLOR=#007700][COLOR=#007700][COLOR=black]$rs = mysql_query("OPTIMIZE TABLE table_name");[/COLOR][/COLOR][/COLOR]
 
[COLOR=black]if(!rs) {[/COLOR]
[COLOR=black]  $errMsg = mysql_error();[/COLOR]
[COLOR=black]  mail($to_error, $subj_error, $errMsg, $hdrs_error);  [/COLOR]
[COLOR=black]   die();[/COLOR]
[COLOR=black]}[/COLOR]
[COLOR=black][/COLOR]
[COLOR=black]?>[/COLOR]
[/COLOR][/COLOR][COLOR=black]

[/COLOR]