Viewed   118 times

I installed XAMPP 1.7.4 (with PHP 5.3.5), the problem is PHP does not display any error messages. E.g. if I connect to MYSQL with mysql_connect() without parameters, PHP will not complain about the required fields.

Why is this?

How can I configure PHP to display errors?



To turn on errors at the script level, include at the top of your script:

ini_set('display_errors', 1);

Alternatively, if it is not a production site and simply a development / testing site, you can turn on error reporting in php.ini. Search it for these settings:

error_reporting  =  E_ALL
;error_reporting  =  E_ERROR
display_errors = On
;display_errors = Off
Tuesday, December 27, 2022

One thing to add to what was said already is that it's paramount that you record any errors in your web application into a log. This way, as Jeff "Coding Horror" Atwood suggests, you'll know when your users are experiencing trouble with your app (instead of "asking them what's wrong").

To do this, I recommend the following type of infrastructure:

  • Create a "crash" table in your database and a set of wrapper classes for reporting errors. I'd recommend setting categories for the crashes ("blocking", "security", "PHP error/warning" (vs exception), etc).
  • In all of your error handling code, make sure to record the error. Doing this consistently depends on how well you built the API (above step) - it should be trivial to record crashes if done right.

Extra credit: sometimes, your crashes will be database-level crashes: i.e. DB server down, etc. If that's the case, your error logging infrastructure (above) will fail (you can't log the crash to the DB because the log tries to write to the DB). In that case, I would write failover logic in your Crash wrapper class to either

  • send an email to the admin, AND/OR
  • record the details of the crash to a plain text file

All of this sounds like an overkill, but believe me, this makes a difference in whether your application is accepted as a "stable" or "flaky". That difference comes from the fact that all apps start as flaky/crashing all the time, but those developers that know about all issues with their app have a chance to actually fix it.

Friday, December 2, 2022

Please try to do the following:

In .htaccess

    # supress php errors
    php_flag display_startup_errors off
    php_flag display_errors off
    php_value docref_root 0
    php_value docref_ext 0

    # enable PHP error logging
    php_flag  log_errors on
    php_value error_log  /correct_path_to_your_website/error_modes/PHP_errors.log

    # general directive for setting php error level
    php_value error_reporting -1

In php file

Instead of intentional mistake in you wrote in your php file you can try doing something like:


    echo $_SERVER['DOCUMENT_ROOT']; // this will enable you to see 
                                    // the correct path to your website dir 
                                    // which should be written in .htaccess 
                                    // instead of correct_path_to_your_website
                                    // (check it just in case)

    $foo = $bar['nope'];// this should generate notice 

    call_undefined(); // this should generate fatal error


Worked good with me)

Hope it'll help.

Wednesday, September 7, 2022

You're sending an ajax request with PrimeFaces <p:commandButton>. Ajax requests have by default no form of feedback (unless PrimeFaces' autoUpdate="true" is been used somewhere). You should be explicitly specifying parts of the view which you'd like to update on ajax response.

One way is specifying the update attribute on <p:commandButton> to point to the client ID of the <h:messages> component.

<h:messages id="messages" ... />
    <p:commandButton ... update=":messages" />

Another way is to replace it by PrimeFaces <p:messages> which has an autoUpdate attribute for the purpose of automatic update on ajax response.

<p:messages ... autoUpdate="true" />
    <p:commandButton ... />

A completely different alternative is to turn off ajax by adding ajax="false" attribute to the button, this way a synchronous postback will be performed which effectively results in a full page update, exactly like as how the standard JSF <h:commandButton> behaves when used without <f:ajax>.

<h:messages ... />
    <p:commandButton ... ajax="false" />

See also:

  • Understanding PrimeFaces process/update and JSF f:ajax execute/render attributes
Saturday, December 3, 2022

My first opinion is that showing a JOptionPane to the user whenever the text field focus is lost could be very annoying for users. I would display an error message when the user hits the OK button of your form. The error message could contain a list of all error messages or only the first one and focus the element with the error.

Another choice would be to use regular JTextField and write your own custom validators. When focus changes, your IntegerValidator (or other implementation) would validate the input string and the UI could display an error or warning icon next to the field, the same as some web applications do.

Tuesday, November 8, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :