Skip to main content
March 6, 2010
Question

Output already started

  • March 6, 2010
  • 1 reply
  • 930 views

Thank you for taking the time to respond.

While I have you on the line can I ask another PHP question?

I call a header file from an index file. In the first code snippet I get the "output already started" when I run the index page. In the second I don't.

<?php

session_start();

require_once ('db_connect_lms.php'); // include the database connection

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

---------------------------------------------------------------------------------------------------------------------------------

<?php

error_reporting(0);

session_start();

require_once ('db_connect_lms.php'); // include the database connection

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

If I comment my error check out, which I did after my dbase connection worked, I got the error. Even removing the line completely causes the same error. I thought the parser was seeing it as a blank line.

I am new to PHP but thought I had this part figured out. Can you explain why the error occurs?

This topic has been closed for replies.

1 reply

David_Powers
Inspiring
March 6, 2010

I have branched this into a separate thread. Please keep to one subject per thread. It makes it easier for everyone to follow.

The problem with output already started is probably caused by whitespace in your connections file. See the following article for a detailed explanation of the most frequent causes: http://kb2.adobe.com/community/publishing/505/cpsid_50572.html.

March 6, 2010

Here is my connection file code:

<?php
define("HOST", "localhost");
# Database user
define("DBUSER", "root");
# Database password
define("PASS", "J1s2m3");
# Database name
define("DB", "my_lms");
# Make the mysql connection
$conn = mysql_connect(HOST, DBUSER, PASS) or  die('Could not connect !<br />Please contact the site\'s administrator.');
$db = mysql_select_db(DB) or  die('Could not connect to database !<br />Please contact the site\'s administrator.');
?>

The <?php at the top is line 1.

There is no whitespace after the ?>, as there are no line numbers (great tip!). I am stumped if the problem is in here.

David_Powers
Inspiring
March 6, 2010

What does the error message actually say? It should tell you where the ouput began.