Forum Moderators: coopster
"Warning: Cannot modify header information - headers already sent by (output started at forms/confirmation.php:27) in forms/confirmation.php on line 188"
it like it is still processing the code even though its in an if statement?
can anyone help please?
CODE:
<?php
$name = $_REQUEST['name'] ;
$company = $_REQUEST['company'] ;
$email = $_REQUEST['email'] ;
$phone = $_REQUEST['phone'] ;
$comments = $_REQUEST['comments'] ;
$subject = $_REQUEST['subject'] ;
$page = $_REQUEST['page'] ;
$message = "From:".$name;
$message .= "\nCompany:".$company;
$message .= "\nEmail:".$email;
$message .= "\nPhone Number:".$phone;
$message .= "\nComments:".$comments;
//checks to see if the name field has been defined (incase someone has gone to the process page directly, if not it redirects back to the form //
if (!isset($_REQUEST['name'])) {
header( "Location: http://www.example.com/forms/index.php" );
//checks if the user has submitted the form with the specified fields left blank//
}
elseif (empty($name) ¦¦ empty($company) ¦¦ empty($email)) {
?>
<?php
}
//if all is well the form is then submitted//
if ( $subject == "Please keep me informed of future seminars" ) {
mail( "enquiries@example.com", "$subject", $message );
header( "Location: http://www.example.com/forms/seminar/thankyou.php" );
}
else {
mail( "enquiries@example.com", "$subject", $message );
header( "Location: http://www.example.com/forms/thankyou.php?page=$page" );
}
?>
[edited by: eelixduppy at 4:21 pm (utc) on April 29, 2008]
[edit reason] exemplified [/edit]
elseif (empty($name) ¦¦ empty($company) ¦¦ empty($email)) {
?> <?php
}
When testing for a condition
if the condition is not what is expected
end it by using exit:
{
// if this or that etc..
echo"go back to ...";
exit();
// exit stop exec
}
<edit> regarding header: you may use it from any script location if OB is turned on in your php.ini</edit>