添加 PDO 连接后,标头重定向停止工作



自从将我的PDO连接添加到我的数据库连接.php文件以来,我所有的标头重定向都停止工作。这是我的连接文件

连接.php

<?php 
$connect_error = 'Sorry there is a problem with the database connection.';
mysql_connect('Localhost', 'customn7', 'I<3deadlifts!') or die($connect_error);
mysql_select_db('customn7_cm') or die($connect_error) or die($connect_error);
?>
<?php   
//PDO database connect
$config['db'] = array(
    'host'      => 'Localhost',
    'username'  => 'customn7',
    'password'  => 'I<3deadlifts!',
    'dbname'    => 'customn7_cm'
);
try {
$db = new PDO('mysql:host=' .$config['db']['host']. ';dbname=' .$config['db']['dbname'], $config['db']['username'], $config['db']['password']);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->exec("SET CHARACTER SET utf8");
} 
catch(PDOException $e) {
echo "ERROR: " . $e->getMessage() . "<br />";
die();
}

?>

这是一个突然不起作用的重定向。此时尚未向浏览器发送任何 HTML。

登录.php

// Post Selected name to current class.
if (isset($_POST['exist_to_class'])){
if (empty($_POST['client_data']) === true){
    $errors [] = 'You much select a client to be added to the class.';
} else {
    if (isset($_POST['client_data']) && !empty($_POST['client_data']));
    foreach ($_POST['client_data'] as $cd){
     exist_client_to_class($db, $cd);
     header('Location: view_class.php?class_id='.$class_id.' ');
    } // foreach $cd
} // else
} //isset

初始化.php

<?php
session_start();
error_reporting(E_ALL);
error_reporting(E_NOTICE);

require 'database/connect.php';
require 'functions/users.php';
require 'functions/general.php';
require 'functions/trainer.php';
?>

连接.php

<?php 
$connect_error = 'Sorry there is a problem with the database connection.';
mysql_connect('Localhost', 'customn7', '**********') or die($connect_error);
mysql_select_db('customn7_cm') or die($connect_error) or die($connect_error);
?>

如果您打印某些内容,任何内容,则不允许发送header。您可能需要重新考虑错误处理。

最新更新