I am getting the

Warning: Cannot modify header information - headers already sent by (output started at /home/bertspar/public_html/ExpressionOfInterest5.php:7) in /home/bertspar/public_html/ExpressionOfInterest5.php on line 53

error and cannot see where I am going wrong. If someone could take a look at the very simple script below, and see if they can see whats wrong, I would REALLY appreciate it. Thanks.

<?php 
session_start();?>
<html>
<head>
<title>Expression Of Interest</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.style1 {color: #FF0000}
.style3 {color: #FF0000; font-size: 10px; }
-->
</style>
<link href="bert2.css" rel="stylesheet" type="text/css">
</head>

<?php
if(isset($_POST['Submit'])){ 
foreach($_POST as $key => $val) 
{ 
$_SESSION[$key] = $val; 
} 

$status = "full";
if($_SESSION['Title'] == NULL) $status = "empty"; 
if($_SESSION['Name'] == NULL) $status = "empty"; 
if($_SESSION['Initial'] == NULL) $status = "empty"; 
if($_SESSION['Surname'] == NULL) $status = "empty"; 
if($_SESSION['Position'] == NULL) $status = "empty"; 
if($_SESSION['Company'] == NULL) $status = "empty"; 
if($_SESSION['Address1'] == NULL) $status = "empty"; 
if($_SESSION['Country'] == NULL) $status = "empty"; 
if($_SESSION['ContactNumber'] == NULL) $status = "empty"; 
if($_SESSION['Email'] == NULL) $status = "empty"; 

if($status == "full") {
$body = $_SESSION['Title']."\n"; 
$body .= $_SESSION['Name']."\n"; 
$body .= $_SESSION['Initial']."\n"; 
$body .= $_SESSION['Surname']."\n"; 
$body .= $_SESSION['Position']."\n"; 
$body .= $_SESSION['Company']."\n"; 
$body .= $_SESSION['Address1']."\n"; 
$body .= $_SESSION['Address2']."\n"; 
$body .= $_SESSION['Address3']."\n"; 
$body .= $_SESSION['Country']."\n"; 
$body .= $_SESSION['ContactNumber']."\n"; 
$body .= $_SESSION['CellNumber']."\n"; 
$body .= $_SESSION['Email']."\n"; 
$email = $_SESSION['Email'];
mail("albert_oflaherty@hotmail.com", "Expression Of Interest in Forum on Public Safety 2006", $body, "From: $email" ); 
empty($_POST);
//session_write_close();
header("Location: Confirmation.htm");
}
}
?>

<body>
<form name="ExpressionInterest" method="post" action="ExpressionOfInterest4.php"> 
       <blockquote>
         <p align="center"><img src="Formtitle.jpg" width="852" height="286" align="middle"></p>
		 <?php
if(isset($_SESSION['Submit'])){ 
echo "Please complete the mandatory fileds. Thank you.";
}
?>
         <p align="center"><strong>REGISTER YOUR INTEREST </strong></p>
         <p align="center">If you would like to register your interest in attending this event, please complete and </p>
         <p align="center">return this form via fax to Norrie Keane at the following number: +353 (0)93 43887. &nbsp; </p>
         <p align="center"><strong><span class="style1">*</span>Title </strong>:
           <select name="Title" size="1" tabindex="1" dir="ltr">
        <option> </option>
        <option>Dr.</option>
        <option>Mr.</option>
        <option>Mrs.</option>
        <option>Miss.</option>
           </select>    
&nbsp;<strong><span class="style1">*</span></strong><strong>Name </strong>:<strong> <input name="Name" type="text" value="<?php if(isset($_SESSION['Name'])){ echo($_SESSION['Name']);}?>" tabindex="2" size="28"> </strong>&nbsp;<strong><span class="style1">*</span>Middle Initial </strong>: <input name="Initial" type="text" value="<?php if(isset($_SESSION['Initial'])){ echo($_SESSION['Initial']);}?>" tabindex="3" size="3" maxlength="3"> </p> </blockquote> <p align="center"><strong><span class="style1">*</span>Surname </strong>: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input name="Surname" type="text" value="<?php if(isset($_SESSION['Surname'])){ echo($_SESSION['Surname']);}?>" tabindex="4" size="67"> </p> <blockquote> <p align="center"><strong><span class="style1">*</span>Position </strong>:&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input name="Position" type="text" value="<?php if(isset($_SESSION['Position'])){ echo($_SESSION['Position']);}?>" tabindex="5" size="67"> </p> <p align="center"><strong> <span class="style1">*</span>Company </strong>: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input name="Company" type="text" value="<?php if(isset($_SESSION['Company'])){ echo($_SESSION['Company']);}?>" tabindex="6" size="67"> </p> <p align="center"><strong><span class="style1">*</span>Address </strong>: <?php echo(str_repeat('&nbsp;',7));?> <input name="Address1" type="text" value="<?php if(isset($_SESSION['Address1'])){ echo($_SESSION['Address1']);}?>"tabindex="7" size="67"> </p> <p align="center"> <?php echo(str_repeat('&nbsp;',23));?> <input name="Address2" type="text" value="<?php if(isset($_SESSION['Address2'])){ echo($_SESSION['Address2']);}?>" tabindex="8" size="67"> </p> </blockquote> <blockquote> <div align="center"></div> <div align="center"> <?php echo(str_repeat('&nbsp;',23));?> <input name="Address3" type="text" value="<?php if(isset($_SESSION['Address3'])){ echo($_SESSION['Address3']);}?>" tabindex="9" dir="ltr" size="67"> </div> </blockquote> <p align="center"> <strong><span class="style1">*</span>Country </strong>:
<?php echo(str_repeat('&nbsp;',6));?> <input name="Country" type="text" value="<?php if(isset($_SESSION['Country'])){ echo($_SESSION['Country']);}?>" tabindex="10" size="67"> </p> <p align="center"><strong> <span class="style1">*</span>Contact No </strong>: &nbsp;&nbsp;<input name="ContactNumber" type="text" value="<?php if(isset($_SESSION['ContactNumber'])){ echo($_SESSION['ContactNumber']);}?>" tabindex="11" size="67"> </p> <p align="center">(Please include country code) <?php echo(str_repeat('&nbsp;',84));?> </p> <p align="center"><strong>Cell Phone </strong>: &nbsp;&nbsp;&nbsp;&nbsp;<input name="CellNumber" type="text" value="<?php if(isset($_SESSION['CellNumber'])){ echo($_SESSION['CellNumber']);}?>" tabindex="12" size="67"> </p> <p align="center">(Please include country code) <?php echo(str_repeat('&nbsp;',84));?> </p> <p align="center"><strong><span class="style1">*</span>Email </strong>: <?php echo(str_repeat('&nbsp;',11));?> <input name="Email" type="text" value="<?php if(isset($_SESSION['Email'])){ echo($_SESSION['Email']);}?>" tabindex="13" size="67"> </p> <p align="center"><strong><span class="style1">*</span></strong> <span class="style3">Mandatory Fields</span></p> <p align="center">By completing this form, you will receive regular, updated Forum information, via email, </p> <p align="center">as it becomes available, and an official invitation and information pack will be forwarded </p> <p align="center">&nbsp;to you via post in due course. </p> <p align="center"> <input name="Submit" type="submit" tabindex="14" value="Submit"> &nbsp;&nbsp;&nbsp;&nbsp;<input name="Reset" type="reset" tabindex="15" value="Reset"> &nbsp;&nbsp;&nbsp; </p> </form> <p align="center">___________________________________________________________________________________ </p> <p align="center">Moyne Park, Tuam, Co. Galway, Ireland &nbsp; </p> <p align="center">Telephone: +353 (0)93 43900 Facsimile: +353 (0)93 43887 &nbsp; Email: nkeane@rivada.com </p> </body> </html>

    Try searching the forums for the words "cannot modify header information".

      I added the ob_start(); and it works fine.

      I'm not really sure how this statement works though.

        5leander5 wrote:

        cannot see where I am going wrong.

        Really?

        From [man]header[/man]:

        Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include(), or require(), functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.

        <html>
        <?php
        /* This will give an error. Note the output
         * above, which is before the header() call */
        header('Location: http://www.example.com/');
        ?>  

        And, as far as:

        I'm not really sure how this statement works though.

        --- that's the next paragraph....

          Write a Reply...