Jump to content

Error Messages into Variable


stig1

Recommended Posts

I would like to put error messages from mysql or my odbc connection into variables to which later I will email them out (already know how to use mail, so no help needed there)

 

How would I put the following into a variable called $error should the sql fail in anyway.

 

$iItemSQL = "insert into items (item, type1, type2, desc1, createdate, lastupdate) values ('".$item."', '".$type1."', '".$type2."', '".$desc1.'", '".$createdate."', '".$lastupdate."')";

$iItems = mysql_query($iItemSQL) or die (mysql_error());

 

Running the above script, if it was to fail would just die and display the error on the screen.

 

Instead of just die and display error, I would like the script to put that error message into a variable to which i can later call, and the script can continue to run.

 

Would this possible work?

 

if(!$iItems){

$error = Error: '.mysql_errno().' '.mysql_error();

}

 

Help is always apprecaited and a huge thankyou in advance.

Link to comment
https://forums.phpfreaks.com/topic/152951-error-messages-into-variable/
Share on other sites

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.