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

时间:2012-11-21 18:03:14

标签: php pdo

由于将我的PDO连接添加到我的db connect.php文件,因此我的所有标头重定向都已停止工作。这是我的连接文件

connect.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发送到浏览器。

的login.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

的init.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';
?>

connect.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);
?>

1 个答案:

答案 0 :(得分:2)

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