-1

Possible Duplicate:
PHP error: Cannot modify header information – headers already sent
“Warning: Headers already sent” in PHP

I many times used header('location:index.php')..but each time it give me error like " Cannot modify header information - headers already sent by"..plz anybody help me....

<?PHP
    $exist=mysql_query("select * from lease where pro_id='".$pro_id."'")
    or die(mysql_error());
    if(mysql_num_rows($exist)>0){header('location:leaseexist.php');} ?>

UPDATE

the error is

Warning: Cannot modify header information - headers already sent by (output started at

/home/content/39/9845539/html/slwebsite/leaseprofile.php:15) in /home/content/39/9845539/html/slwebsite/leaseprofile.php on line 19

and line 19 is

 if(mysql_num_rows($exist)>0){header('location:leaseexist.php');}
Community
  • 1
  • 1
  • show us the full error ............... some times it shows the line which error occurs – Kanishka Panamaldeniya Nov 22 '12 at 10:59
  • 1
    The error occurs only when something is outputted before `header` is used. May be your query above is yielding error – WatsMyName Nov 22 '12 at 11:00
  • The best explanation: http://stackoverflow.com/questions/8028957/warning-headers-already-sent-in-php – Jonathan Spiller Nov 22 '12 at 11:01
  • Warning: Cannot modify header information - headers already sent by (output started at /home/content/39/9845539/html/slwebsite/leaseprofile.php:15) in /home/content/39/9845539/html/slwebsite/leaseprofile.php on line 19 ......and line 19 is if(mysql_num_rows($exist)>0){header('location:leaseexist.php');} – ashish kansara Nov 22 '12 at 11:01
  • @ashishkansara try commenting that line and see what happens, any other error message? – WatsMyName Nov 22 '12 at 11:03
  • It is not line 19 causing the issue. The issue is caused before this line. When you set the Header using header("Location:......"); you need to make sure that NOTHING is outputted to screen. – Chris Nov 22 '12 at 11:06
  • @ LoVeSmItH: you are right...i did echo there..now i removed and it is working...thanks bro..also thanks to others.. – ashish kansara Nov 22 '12 at 11:06
  • @ Chris: yes u r right...there was 1 line i.e echo...ir gave me problem – ashish kansara Nov 22 '12 at 11:07

3 Answers3

2

Should be check white space at first line.

Bhanwar
  • 31
  • 1
1

Try @flush(); at the upper side of each header location. For example:

if(mysql_num_rows($exist)>0){
 @flush();
 header('location:leaseexist.php');
}
Prem
  • 697
  • 3
  • 10
0

it can be because either your file leaseexist.php contains some invalid code which prompts for header error or your current script has some html code mixed up. make sure you do not send any bites before headers are sent,else it will throw an error.header should be the first thing to be sent to the browser

thepiyush13
  • 1,321
  • 1
  • 8
  • 9