php - 显示所有错误和警告

标签 php debugging warnings

更新 2:

我现在从 .php 文件中删除了以下内容:

<?php error_reporting( E_ALL ); ?>

我在 php.ini 中设置 display_erros 如下:

display_errors = On

错误报告在php.ini中设置如下:

error_reporting = E_ALL | E_STRICT

重新启动 Apache 后,我仍然没有收到任何错误/警告。

更新 1:

我已将 php.ini 中的 error_reporting 更改为:

error_reporting = E_ALL & ~E_DEPRECATED

error_reporting = E_ALL | E_STRICT

之后我重新启动了 Apache,例如

/etc/init.d/apache2 restart

但页面仍然不会显示任何类型的错误/警告。

原始问题:

以下脚本正在生成警告,因为 $err 在 if 语句中。为什么在 Web 浏览器的 PHP 页面上没有显示此警告?

我必须查看 Apache 日志才能看到警告。另外,如果我故意将“插入”更改为“删除”,它不会在PHP页面上显示错误。为什么错误没有显示在实际的 PHP 页面上?

<?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>

最佳答案

可以在 php.ini 或您的 Apache 配置文件中关闭显示错误。

你可以在脚本中开启它:

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

您应该会在 PHP 错误日志中看到相同的消息。

关于php - 显示所有错误和警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5438060/

相关文章:

angular - 无法在 Angular 应用程序上设置断点

php - PHP-自定义验证器函数并传递未设置的变量

php - Doctrine 2 : Query result as associative array

PHP MySQL 如果日期和时间不可用添加到警报消息

debugging - Gradle-Gradle 2.1的编译问题

windows - OllyDbg 不能在 Windows 7 x64 上运行

Android Studio 警告 : Using incompatible plugins for the annotation processing

c++ - 在 MSVC++2010 中禁用警告

php - 无法访问空属性 - Sendgrid

php - 获取登录用户的列表 PHP