Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

redirect after form submission

Posted on 2004-09-15
8
Medium Priority
?
225 Views
Last Modified: 2008-02-26
Hi,

I'm having a problem using the header function...it 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.
0
Comment
Question by:lienny
  • 6
  • 2
8 Comments
 
LVL 27

Expert Comment

by:Diablo84
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)
0
 
LVL 27

Expert Comment

by:Diablo84
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.
0
 
LVL 27

Expert Comment

by:Diablo84
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

ob_end_flush();
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:lienny
ID: 12065426
been doing some research...it won't work if I call includes before that.
0
 
LVL 27

Accepted Solution

by:
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
0
 
LVL 27

Expert Comment

by:Diablo84
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:

javascript:

<script language="JavaScript">
window.location="http://www.site.com/page.html";
</script>

or Meta Refresh (between the head tags)

<meta http-equiv="refresh" content="0;URL=http://www.site.com/page.html">

0
 

Author Comment

by:lienny
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
0
 
LVL 27

Expert Comment

by:Diablo84
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.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses how to create an extensible mechanism for linked drop downs.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

886 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