MySql problems

Hi all,

We have a website for selling books, developed with HTML, PHP y MySQL.
In a certail page, where the website interacts with the database, in a few cases only part of the page is loaded, so the customer is not able to complete the purchase.

An example of the PHP code is:
$insert_quotation = “INSERT INTO Quotations_DSStgo(QuotationID, Date, Status, CustomerID, BookID, ClassID) VALUES (‘NULL’,‘NULL’, ‘0’, ‘$CustomerID’,‘$Book_ID’, ‘$ClassID’)”;
mysql_query($insert_quotation, $db_handle) or die(mysql_error());

My question is: in case of an error, how can I keep the code but send the error message information to a log in order I am able to see what is happening?
I think the problem is in certain cases an error happens and “die”, but I do not have information about the error, so I am unable to solve it.

Thanks a lot!!!
Sir_Arcturus

Hi there,

The first question is, is it a PHP error or a MySQL error?
I would guess PHP, as whatever you are attempting to do in the PHP code is causing the page to choke.

Both PHP and MySQL have error logs, but whether you have access to them is another question.
What is your hosting set up?

What do you see listed under “error_log” when you do phpinfo()?

Hi,

Thanks a lot.
Unfortunately when I run this command I get:
phpinfo() has been disabled for security reasons

Sorry for that …

No drama.
Are you on shared hosting?

Yes, I am …

While shared hosting is adequate for a lot of purposes, one annoyance is that they don’t normally provide access to Apache error logs.
So, what you can then do, is simply create your own error logs for certain pages:

<?php
error_reporting(0); // Turns off all error reporting.

function userErrorHandler($errno, $errmsg, $filename, $linenum, $vars)
{
    $dt = date('Y-m-d H:i:s (T)');

    // define an assoc array of error string
    $errortype = array (
                E_ERROR => 'Error',
                E_WARNING => 'Warning',
                E_PARSE => 'Parsing Error',
                E_NOTICE => 'Notice',
                E_CORE_ERROR => 'Core Error',
                E_CORE_WARNING => 'Core Warning',
                E_COMPILE_ERROR => 'Compile Error',
                E_COMPILE_WARNING => 'Compile Warning',
                E_USER_ERROR => 'User Error',
                E_USER_WARNING => 'User Warning',
                E_USER_NOTICE => 'User Notice',
                E_STRICT => 'Runtime Notice'
                );
								
    // set of errors for which a var trace will be saved.
    $user_errors = array(E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE);

    $err = "<errorentry>\
";
    $err .= "\	<datetime>" .$dt. "</datetime>\
";
    $err .= "\	<errornum>" .$errno. "</errornum>\
";
    $err .= "\	<errortype>" .$errortype[$errno]. "</errortype>\
";
    $err .= "\	<errormsg>" .$errmsg. "</errormsg>\
";
    $err .= "\	<scriptname>" .$filename. "</scriptname>\
";
    $err .= "\	<scriptlinenum>" .$linenum. "</scriptlinenum>\
";

    if (in_array($errno, $user_errors)) {
        $err .= "\	<vartrace>" .wddx_serialize_value($vars, 'Variables'). "</vartrace>\
";
    }
    $err .= "</errorentry>\
\
";

    // save to the error log file, and e-mail me if there is a critical user error.
    error_log($err, 3, 'error_log.log');
		
    if ($errno == E_USER_ERROR) {
        mail('you@address.com', 'Critical User Error', $err);
    }
}
$new_error_handler = set_error_handler('userErrorHandler');

Save this code into a PHP file, upload it to your server and then include it into the page that is causing you problems (using the include() method).
What it’ll do is to log any errors the PHP script creates into a file called error_log.log in the same directory.
You can also set your mail at the bottom of the script, so that it mails you in the event of a critical user error (or any error if you so desire).
I can’t claim credit for the code. I found it here: http://www.hotscripts.com/blog/php-error-log-file-archive/

Not sure if this will help you solve the problem, but should bring you a step forward at least.

Thanks a lot, I have much more info now.

Based on that, I created a new post. I’d appreciate if you can take a look:

Thanks again!!