Page 1 of 1

Warning: Cannot modify header information - headers already

Posted: Tue Apr 27, 2010 7:51 pm
by soma56
I'm sure there's a very simple solution to this that I can't see. I'm bringing in some form data and if one field is empty then I'd like the user redirected to a different page.

Code: Select all

//Info brought in from form
$engravedtext = trim($_POST["engravedtext"]);  

if ($engravedtext=="")
{ 
   //go here
   header ("page1.php");
} 
else 
{ 
   //else go there
   header ("page2.php");
} 


?>
I'm brand new to php and everything 'logically looks right'. If the engraved text field is empty go to this page, if not go to that page. I tried using the 'redirect' function as well with no luck. Suggestions?

Re: Warning: Cannot modify header information - headers alre

Posted: Tue Apr 27, 2010 9:29 pm
by Christopher
You can't have any output before the header(). Check for any echo or characters outside php tags.

Re: Warning: Cannot modify header information - headers alre

Posted: Wed Apr 28, 2010 3:17 am
by Eran
Also in the future, please use the forum search function before posting. This is just from a couple of days ago
viewtopic.php?f=1&t=115746

Re: Warning: Cannot modify header information - headers alre

Posted: Wed Apr 28, 2010 12:49 pm
by soma56
Christopher wrote:You can't have any output before the header(). Check for any echo or characters outside php tags.
Not too sure I understand, but it led me to an hour of reading in which I was able to solve my issue. Thanks Christopher.

All I wanted to do was to redirect a user to one of two pages based on whether or not a particular field was empty (or not). In this case it was 'text engraving'.

Code: Select all

<?PHP

if ($engravedtext=="")   
{    
   echo '<META HTTP-EQUIV="Content="0; URL=success.php">';      
}    
else    
{    
   echo '<META HTTP-EQUIV="Content="0; URL=retry.php">';      
}  

?>
pytrin wrote:Also in the future, please use the forum search function before posting. This is just from a couple of days ago
viewtopic.php?f=1&t=115746
Being completely new to php I'm not certain how this page can help me at this time, perhaps in a few months I'll understand it better :)