Alfred Alfred - 24 days ago 5
MySQL Question

Cannot modify header information - headers already sent by

I read a topic about this header but could not make it work for my program. I removed html and space before, but still cannot see what is wrong. the connect.php file purpose is to connect to a database and I use app_config.php file to call handle_error function from connect.php to print any error occurring while attempting to connect to database. Great thanks for your help!

Error is:


Warning: Cannot modify header information - headers already sent by (output started at /home3/alfredbiz/public_html/phpMM/ch05/scripts/connect.php:1) in /home3/alfredbiz/public_html/phpMM/ch05/app_config.php on line 12


here is connect.php

<?php
//appel le fichier de mot de passe
require_once '/home3/alfredbiz/public_html/phpMM/ch05/app_config.php';
require_once '/home3/alfredbiz/public_html/phpMM/ch05/app_connexion.php';

//database connexion
$link = mysqli_connect(DATABASE_HOST, DATABASE_USERNAME, DATABASE_PASSWORD, DATABASE_NAME);

// check connection
if (!$link) {
$user_error_message = "there was a problem connecting to the database that holds the information we need to get you connected.";
$system_error_message = mysqli_connect_error();
handle_error($user_error_message, $system_error_message);
}

//editer les tables avec controle d erreur
$result = mysqli_query($link, "show tables");
if(!$result){
die("<p>Error in Listing tables: " .mysql_error() . "</p>");
}
echo "<p> requette executee avec success</p>";
?>


app_config.php

<?php
//set up debug mode
define("DEBUG_MODE", true);

function debug_print($message) {
if(DEBUG_MODE) {
echo $message;
}
}

function handle_error($user_error_message, $system_error_message) {
header("location: /home3/alfredbiz/public_html/phpMM/ch05/scripts/show_error.php?" ."error_message={$user_error_message}&" ."system_error_message= {$system_error_message}");
exit();
}
?>

Answer

This is a common error caused by BOM (Byte Order Mark). The indicator for this is the fact that the output started on line 1.

See the duplicate thread How to fix "Headers already sent" error for the resolution.

Comments