显示所有错误和警告 [英] Showing all errors and warnings

查看:161
本文介绍了显示所有错误和警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新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


to


error_reporting = E_ALL | E_STRICT


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


/etc/init.d/apache2 restart


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

ORIGINAL QUESTION:



以下脚本正在生成警告,因为$ err在if语句里面。为什么在网页浏览器的php页面上不显示此警告?我必须看看apache日志才能看到警告。此外,如果我将insert into更改为delete into,则不会在php页面上显示错误。为什么错误不显示在实际的PHP页面上?

 <?php 
error_reporting(E_ALL);
?>

< html>
< head>
< title>< / title>
< link rel =icontype =image / pnghref =favicon.ico>

<?php
if($ _SERVER ['REQUEST_METHOD'] =='POST'){
$ err = array();

if(empty($ _POST ['display_name']))$ err [] =需要显示名称字段;
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 - >准备(删除到table1(display_name,email,密码)值(: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 - >执行();

$ STH = $ DBH - >准备(删除到table2(username,status,users_id)值(: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 - >执行();

$ DBH = null;
} catch(PDOException $ e){
echo $ e - > getMessage();
}

header(Location:。$ _ SERVER ['PHP_SELF']);
退出;
} 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 =textname =referer/>< br />< br />

名称:< br />
< input type =textname =display_namevalue =<?php echo $ form ['display_name'];?> />< br />< br />

电子邮件:< br />
< input type =textname =emailvalue =<?php echo $ form ['email'];?> />< br />< br />

密码:< br />
< input type =textname =passwordvalue =<?php echo $ form ['password'];?> />< br />< br />

< input type =submitvalue =register/>
< / form>
< / body>
< / html>


解决方案

显示错误可能会在 php.ini 或您的Apache配置文件。



您可以在脚本中打开它:

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

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


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 an 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 apache logs to see the warning. Also, if I delibarately 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>

解决方案

Display errors could be turned off in the php.ini or your Apache config 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.

这篇关于显示所有错误和警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆