Click to See Complete Forum and Search --> : Error: Cannot modify header info, blah blah blah...bite me


Daot Lagorille
10-29-2003, 09:21 AM
I have a spiffy survey form that works great, except that it doesn't because when I submit I get this error:

Cannot modify header information - headers already sent by

I have traced the problem down to this:

I have several select field in the page that display contingent upon the value of a variable that is sent from a previous screen. The variables are all declared at the top, with the values equal to the HTTP_GET_VARS.

The dynamic display code looks like this:

<?php if ($varCOMM == 'yes') { ?>

<select>blah</select>

<?php } ?>


I have 8 of the above bits. With the above php commented out - no problem.

With it, the aftorementioned error.

Please send help, and food.

Daot Lagorille
10-29-2003, 09:24 AM
PS: I should add that the line referred to in the error is the redirect after the form submit function:

$insertGoTo = "done.php";
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));

It is that last line that is referred to.

Daot Lagorille
10-29-2003, 10:47 AM
Never mind -

For anyone out there who is as stupid as me, this is what the problem was:

Because each of those selects displayed contingent upon certain variable values, if they did not display, nothing at all was sent to the insert statement. To fix, I included an "else" on each one:
<?php if ($varCOMM == 'yes') { ?>

<select>blah</select>

<?php } else { ?>
[hidden input tag with "n/a" value]
<?php } ?>

At that, folks, is what we in the business like to call...something...