问题描述
更新2:
我现在已从.php文件中删除以下内容:
<?php error_reporting(E_ALL); ?>
我已经在php.ini中设置了display_erros,如下所示:
错误报告设置为以下php.ini
重新启动apache后,我仍然没有收到错误/警告。
更新1:
我从php.ini更改了error_reporting:
to
之后我重新启动了apache,例如
但该页面仍然不会显示任何类型的错误/警告。 / 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:
error reporting is set to the following in php.ini
After restarting apache, I still get no errors/warnings.
UPDATE 1:
I have changed error_reporting in php.ini from:
to
After which I restarted apache, e.g.
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.
这篇关于显示所有错误和警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!