Can't send headers. Output already started

My PHP files that include the following database.php file generate the can’t send headers. Output already started error. I have recreated the file and have removed any white space. Does anybody know what would cause the error in the following code:

<?php
$dbHost = "www.a2zloads.com";
$dbuser = "site4_webusers";
$dbpass = "password";
$dbname = "site4_websiteloads";
$conn = mysqli_connect($dbHost, $dbuser, $dbpass, $dbname);
if (!$conn)
    {
        echo "NOT connected to: " . $dbname . "<br>";
        die("Database connection failed!");
    }
 ?>

The connection does appear to work as I am getting entries in my database.

You can NOT send out anything to the browser before a < HTML > commaned.
Therefore, if the echo or die is processed it will be sent to the browser.
Also, with just that code, you can NOT be getting anything in your database because it is no code that creates anything in a DB.
Are you showing us all your code?

The error message should state (there was a couple of php versions where it didn’t) where the output is being sent at. Post the full error message if you need someone to interpret it for you.

The connection is working so the die and if are not giving me output. I even removed the whole if statement and still get the error. This is all the code that is called from many of my other pho files that need a database connection. I get the same error code. I read that it could be issues with whitespace so I even recreated just those lines in a new file. I contacted the host support and had to escalate to level 2

Cannot modify header information - headers already sent by (output started at /home4/atwozloa/public_html/loads/includes/database.php:1) in /home4/atwozloa/public_html/loads/includes/login-inc.php on line 37

Well, you showed us 10 lines of code.
Show us line number 36 to 38…

The output is on line 1 of database.php. If there are no physical characters in the file before the <?php tag, the problem is most likely because that file has a UTF-8 character encoding with a BOM (Byte Order Mark) character. Open the file with your editor, find the Encoding or similar menu, pick a character encoding that doesn’t include the BOM character, then save the file.

you are the bomb. that was it

Sponsor our Newsletter | Privacy Policy | Terms of Service