Cannot modify header information

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
salmon
Forum Newbie
Posts: 9
Joined: Tue Jun 24, 2008 5:03 pm

Cannot modify header information

Post by salmon »

I'm getting this error and I do not know why. :?:

Code: Select all

Warning: Cannot modify header information - headers already sent by (output started at /home/username/public_html/page.php:5) in /home/username/public_html/page.php on line 210
The page has both html and php code
html code then

Code: Select all

 
<?php 
                  
if ($_POST) 
{
    if (trim($_POST['firstName'])=='' OR 
        trim($_POST['lastName'])=='' OR
        trim($_POST['gender'])=='' OR
        trim($_POST['address1'])=='' OR     
        trim($_POST['city'])=='' OR
        trim($_POST['state'])=='' OR
        trim($_POST['zipcode'])=='' OR
        trim($_POST['phoneNumber'])=='' OR
        trim($_POST['email'])=='' OR        
        trim($_POST['areaExpertise'])=='' OR
        trim($_POST['yearsExperience'])=='' OR
        trim($_POST['degree'])=='' OR
        trim($_POST['licenseCertif'])=='' OR        
        trim($_POST['reasonConsult'])=='' OR
        trim($_POST['compSkills'])=='' OR
        trim($_POST['powerpoint'])=='' OR
        trim($_POST['publicSpeaking'])=='' OR
        trim($_POST['salesTraining'])=='' OR                        
        trim($_POST['certify'])=='') { 
    
    $errors=''; 
    
        if (trim($_POST['firstName'])=='') 
        $errors.="<li>Enter first name.</li>\n";  
    
        if (trim($_POST['lastName'])=='') 
        $errors.="<li>Enter your last name.</li>\n"; 
                
        if (trim($_POST['gender'])=='') 
        $errors.="<li>Enter your gender.</li>\n";
                
        if (trim($_POST['address1'])=='') 
        $errors.="<li>Enter your address.</li>\n";
                
        if (trim($_POST['city'])=='') 
        $errors.="<li>Enter your city.</li>\n";
                
        if (trim($_POST['state'])=='') 
        $errors.="<li>Enter your state.</li>\n";                
                
        if (trim($_POST['zipcode'])=='') 
        $errors.="<li>blah, blah, blah</li>\n";
        
        if (trim($_POST['phoneNumber'])=='') 
        $errors.="<li>blah, blah, blah</li>\n";
        
        if (trim($_POST['email'])=='') 
        $errors.="<li>blah, blah, blah</li>\n";
        
        if (trim($_POST['areaExpertise'])=='') 
        $errors.="<li>blah, blah, blah</li>\n";
        
        if (trim($_POST['yearsExperience'])=='') 
        $errors.="<li>blah, blah, blah</li>\n"; 
                
        if (trim($_POST['degree'])=='') 
        $errors.="<li>Enter your degree(s)</li>\n"; 
                
        if (trim($_POST['licenseCertif'])=='') 
        $errors.="<li>blah, blah, blah</li>\n"; 
                
        if (trim($_POST['reasonConsult'])=='') 
        $errors.="<li>blah, blah, blah</li>\n"; 
                
        if (trim($_POST['compSkills'])=='') 
        $errors.="<li>blah, blah, blahli>\n"; 
                
        if (trim($_POST['powerpoint'])=='') 
        $errors.="<li>blah, blah, blahli>\n"; 
                        
        if (trim($_POST['publicSpeaking'])=='') 
        $errors.="<li>blah, blah, blahli>\n"; 
        
        if (trim($_POST['salesTraining'])=='') 
        $errors.="<li>blah, blah, blahli>\n"; 
                        
        if (trim($_POST['certify'])=='') 
        $errors.="<li>You must blah, blah, blah...</li>\n"; 
 
    
    echo "<span class=\"txtRedLg\">Errors were encountered:</span>\n"; 
 
    // If there are errors display errors above the form again.
    echo "<ul>\n";  
    echo "<span class=\"txtsmallred\">$errors</span>\n"; 
    echo "</ul></span>\n"; 
 
    } 
    else { 
    
    // All fields were submitted 
        
    // Redirect to a "thank you, we will be in touch" page.
    header("Location: http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "page.php");
 
    } 
}
 
?>
 
then

Code: Select all

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
then html code
WebbieDave
Forum Contributor
Posts: 213
Joined: Sun Jul 15, 2007 7:07 am

Re: Cannot modify header information

Post by WebbieDave »

Ensure there is no whitespace (including line breaks) before your PHP tags. That is considered "output."
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: Cannot modify header information

Post by Eran »

make sure you aren't outputting anything before the 'header' function is invoked. Headers can not be sent after output was already sent to the browser.
Post Reply