Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


redirect after form submission

Posted on 2004-09-15
Medium Priority
Last Modified: 2008-02-26

I'm having a problem using the header gives me an error saying headers already sent.  The issue I think lies in the fact that I have a page that displays a query from a previous form and then another form that lets the user addes infinite numbers of records.  After submit I'd like to take the user to a new page that list what was just inserted.
Question by:lienny
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 2
LVL 27

Expert Comment

ID: 12065308
header redirects must go before ANY output which includes:

php echo/print
new lines
html tags

Ideally it should go right at the top of the page (just after the form processing if applicable)
LVL 27

Expert Comment

ID: 12065336
You can run database queries before redirecting as long as you don't output any results, any such output (as listed above) will result in the header already sent error because the header must be sent before the output content is generated.
LVL 27

Expert Comment

ID: 12065377
you can use output buffering to work around it but its really better to just fix the script, example:

ob_start(); //top of page

//various code and header redirect

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 12065426
been doing some won't work if I call includes before that.
LVL 27

Accepted Solution

Diablo84 earned 500 total points
ID: 12065452
If your includes generate output data they will cause the same error

You can include includes before the header redirect as long as their contents only deal with calculation and processing
LVL 27

Expert Comment

ID: 12065491
If its going to cause a problem modifying your script to work because of the way it is set up you might wish to consider an alternative redirect method:


<script language="JavaScript">

or Meta Refresh (between the head tags)

<meta http-equiv="refresh" content="0;URL=">


Author Comment

ID: 12065520
thanks for coming to my rescue again!...but i got it to work...just need to take a break from looking at the code before I knew what I was doing wrong. =D
LVL 27

Expert Comment

ID: 12065577

In my book coffee is the short term solution but a good nights sleep and fresh eyes renders the best results.... if only there was more time in the day.

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question