1

自从将我的 PDO 连接添加到我的 db connect.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
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);
?>
4

1 回答 1

2

如果你打印一些东西,任何东西,你都不能发送header. 您可能需要重新考虑错误处理。

于 2012-11-21T18:06:59.640 回答