Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Showing all errors and warnings [duplicate]

UPDATE 2:

I have now removed the following from the .php file:

<?php error_reporting( E_ALL ); ?> 

I have set display_erros in php.ini as follows:

display_errors = On

Error reporting is set to the following in php.ini:

error_reporting = E_ALL | E_STRICT

After restarting Apache, I still get no errors/warnings.

UPDATE 1:

I have changed error_reporting in php.ini from:

error_reporting = E_ALL & ~E_DEPRECATED

to

error_reporting = E_ALL | E_STRICT

After which I restarted Apache, e.g.

/etc/init.d/apache2 restart

But the page will still not display errors/warnings of any kind.

ORIGINAL QUESTION:

The following script is generating a warning because the $err being inside the if statement. Why is this warning not being displayed on the PHP page in a web browser?

I have to look at the Apache logs to see the warning. Also, if I deliberately change the "insert into" to "delete into", it does not display an error on the PHP page. Why are the errors not displaying on the actual PHP page?

<?php     error_reporting(E_ALL); ?>  <html>     <head>         <title></title>         <link rel="icon" type="image/png" href="favicon.ico">          <?php             if ($_SERVER['REQUEST_METHOD'] == 'POST') {                 $err = array();                  if (empty( $_POST['display_name']))                     $err[] = "display name field is required";                 if (empty( $_POST['email']))                     $err[] = "email field is required";                 if (empty( $_POST['password']))                     $err[] = "password field is required";                  if (!$err) {                     try {                         $DBH = new PDO("mysql:host=localhost;dbname=database1", "user", "pass");                         $DBH->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);                          $STH = $DBH->prepare("delete into table1 (display_name, email, password) values ( :display_name, :email, :password )");                          $STH->bindParam(':display_name', $_POST['display_name'], PDO::PARAM_STR, 100);                         $STH->bindParam(':email', $_POST['email'], PDO::PARAM_STR, 100);                         $STH->bindParam(':password', $_POST['password'], PDO::PARAM_STR, 100);                          $STH->execute();                          $STH = $DBH->prepare("delete into table2 ( username, status, users_id ) values ( :username, :status, :users_id )");                          $strStatus = 1;                          $STH->bindParam(':username', $_POST['display_name'], PDO::PARAM_STR, 100);                         $STH->bindParam(':status', $strStatus, PDO::PARAM_INT, 1);                         $STH->bindParam(':users_id', $_POST['referer'], PDO::PARAM_INT, 1);                          $STH->execute();                          $DBH = null;                     }                     catch (PDOException $e) {                         echo $e->getMessage();                     }                      header("Location: " . $_SERVER['PHP_SELF']);                     exit;                 }                 else {                     foreach ($_POST as $key => $val) {                         $form[$key] = htmlspecialchars($val);                     }                 }             }             else {                 $form['display_name'] = $form['email'] = $form['password'] = '';             }         ?>     </head>      <body>         <?php foreach($err as $line) { ?>         <div style="error"><?php echo $line; ?></div>         <?php } ?>          <h1>Register</h1>          <form method="post">             Referers id:<br/>             <input type="text" name="referer" /><br/><br/>              Name:<br/>             <input type="text" name="display_name" value="<?php echo $form['display_name']; ?>" /><br/><br/>              Email:<br/>             <input type="text" name="email" value="<?php echo $form['email']; ?>" /><br/><br/>              Password:<br/>             <input type="text" name="password" value="<?php echo $form['password']; ?>" /><br/><br/>              <input type="submit" value="register" />         </form>     </body> </html> 
like image 831
oshirowanen Avatar asked Mar 25 '11 20:03

oshirowanen


People also ask

How do I show all errors in PHP?

Quickly Show All PHP Errors The quickest way to display all php errors and warnings is to add these lines to your PHP code file: ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL);

Which of the following parameters needs to be set for capturing all errors and displaying them to the user at once?

error_reporting(E_ALL); ini_set('display_errors', '1');

Which of the following PHP directive is used to display all the errors except notices?

error_reporting: It displays all level errors except E-NOTICE, E-STRICT, and E_DEPRECATED level errors. display_errors: By default, the value of display_errors is off.


2 Answers

Display errors could be turned off in the php.ini or your Apache configuration file.

You can turn it on in the script:

error_reporting(E_ALL); ini_set('display_errors', '1'); 

You should see the same messages in the PHP error log.

like image 106
5 revs, 4 users 62% Avatar answered Oct 08 '22 23:10

5 revs, 4 users 62%


I was able to get all errors via the below code:

ini_set('display_startup_errors', 1); ini_set('display_errors', 1); error_reporting(-1); 
like image 32
Rajesh Patel Avatar answered Oct 08 '22 21:10

Rajesh Patel