Warning: Cannot modify header information...

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

sunLotus
New php-forum User
New php-forum User
Posts: 1
Joined: Wed Jul 09, 2014 2:43 am

Warning: Cannot modify header information...

Postby sunLotus » Wed Jul 09, 2014 2:53 am

(it worked in WAMP, it doesn't work on online server; I think I don't put a correct path in header())

Warning: Cannot modify header information - headers already sent by (output started at /home/u506537884/public_html/mituri.php:154) in /home/u506537884/public_html/comentarii/blank.php on line 22

in the public_html I have:

folder1, folder2, comments_folder,folder4,....
file1.php,file2.html,myths.php,....


In myths.php I have:

....................

Code: Select all

<?php  (line 154)
      require 'comments/blank.php';
      require 'comments/displayCom.php';
   ?>

....................

In blank.php I have:

Code: Select all

<?php
// Report all errors except E_NOTICE
error_reporting(E_ALL ^ E_NOTICE);

require('connect.php');

//taking data from the form
$name=$_POST['name'];
$comment=$_POST['comment'];
$submit=$_POST['submit'];

if($submit){
   if($name && $comment){
      $insert = mysql_query("INSERT INTO comment(name,comment) VALUES('$name','$comment')");
      
      /*If I don't use HEADER to something(I want to HEADER to the same page, myths.php),
      it inserts another time the last comment in the database when I refresh the page;
      also the comment appears again in myths.php....and so on with each REFRESH of the myths.php....the last comment is repeating(on the page, in the database)
      
       header('Locaton: ../myths.php');  (line 22)
      }
}

?>


(html)
the form with fields: NAME, COMMENT, SEND button(to myths.php)
(/html)

In displayCom.php:
the comments are displayed from the database

kladrian
New php-forum User
New php-forum User
Posts: 12
Joined: Thu Aug 14, 2014 1:13 am
Contact:

Re: Warning: Cannot modify header information...

Postby kladrian » Thu Aug 14, 2014 11:25 am

hi,

first of all it's best practice to remove '?>' at the end of each php file or ... maybe it's better to say that is malpractice to write '?>' at the end of the file :)

then the problem is not the path of the header but something else before.

This is a well know error that means you are trying to modify header information when there is already an output.
The output could be a warning, a notice or even single white space left at the end of included file (that's the reason why it's malpractice to leave '?>' at the end of the file)

---
kladrian


Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 1 guest