最佳答案
更新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 < / p >
来
error_reporting = E_ALL | E_STRICT
在这之后,我重新启动了Apache。
/etc/init.d /输入重启
但是页面仍然不会显示任何类型的错误/警告。
最初的问题:
下面的脚本将生成一个警告,因为$err位于if语句中。为什么这个警告没有显示在web浏览器的PHP页面上?
我必须查看Apache日志才能看到警告。另外,如果我故意将“insert into”更改为“delete into”,它也不会在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>