1

I have a form that, on submit, is going to a PHP file. Here the form is processed and sent to a MySQL database for storage. After this is done I want the page to, automatically, send me to the next page wich contains another form that has to be filled in (this continues a few times).

I know that you can use
header('Location: HERE YOURE LINK ');
for sending you to the next page, but it doesn't work.

In my PHP file I have some basic stuff:
Request form, process data, INSERT INTO database....

When I put the "header....."-code after these PHP commands it returns an error, and the same thing happens when I place it in front of the PHP commands.
It keeps returning the error:
Cannot modify header information - headers already sent by .... on line 17

I hope someone can help me, and that I have given you all the information you need to help me. I've been searching all day but still haven't found the solution.

Thanks in advance!
Milaan

Jonas
  • 121,568
  • 97
  • 310
  • 388
Milaan
  • 247
  • 5
  • 14

4 Answers4

4

You need to make sure the header(...); line is called before any other text or headers are sent.

Dutchie432
  • 28,798
  • 20
  • 92
  • 109
  • Yes that might work to, but i've used the solution that Harish presented me and that worked perfectly! Nevertheless thanks for youre time! – Milaan Jan 25 '11 at 17:18
1

The "headers already sent" error is usually caused by having white space before or after the opening and closing PHP tags (<?php . . . ?>).

Use of ob_start() also helps.

This function will turn output buffering on. While output buffering is active no output is sent from the script (other than headers), instead the output is stored in an internal buffer.

Harish
  • 2,311
  • 4
  • 23
  • 28
0

Putting the html tag before the header() blocks it. Please check.

Markku
  • 104
  • 4
  • Yes that might be it :) But the solution from Harish worked perfecly. But thanks for youre time! – Milaan Jan 25 '11 at 17:20
-1

A detailed description of your very common problem may be found at the following link:

http://www.phpbuilder.com/board/showthread.php?t=10262775

Kevin
  • 1,889
  • 14
  • 11