Question
Dreaded "headers already sent" error
I'm getting a "headers already sent" error and I can't figure
out why.
I have checked for and eliminated all whitespace in my php include files
and still I'm getting the error:
> Warning: Cannot modify header information - headers already sent by
> (output started at
> /Users/brett/vhosts/modules/admin/Products/add_div.inc.php:51)
> in /Users/brett/vhosts/modules/admin/Products/update_grp.inc.php on
> line 44
After updating a table record, I am trying to redirect to a page
containing accordion panels populated with table LIST pages. Here is my
redirect:
>
> if ($Result1) {
> header('Location: http://' . $_SERVER['HTTP_HOST'] .
> dirname($_SERVER['PHP_SELF']) .
> '/admin.php?content=Products/seeSelections');
> exit;
> }
I have looked at the include file listed in the error message and can
find no problem. Here is the code:
> <?php
> if (!function_exists("GetSQLValueString")) {
> function GetSQLValueString($theValue, $theType, $theDefinedValue = "",
> $theNotDefinedValue = "")
> {
> $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) :
> $theValue;
>
> $theValue = function_exists("mysql_real_escape_string") ?
> mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
>
> switch ($theType) {
> case "text":
> $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
> break;
> case "long":
> case "int":
> $theValue = ($theValue != "") ? intval($theValue) : "NULL";
> break;
> case "double":
> $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'"
> : "NULL";
> break;
> case "date":
> $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
> break;
> case "defined":
> $theValue = ($theValue != "") ? $theDefinedValue :
> $theNotDefinedValue;
> break;
> }
> return $theValue;
> }
> }
>
> $editFormAction = $_SERVER['PHP_SELF'];
> if (isset($_SERVER['QUERY_STRING'])) {
> $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
> }
>
> if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "addDiv")) {
> $insertSQL = sprintf("INSERT INTO divisions (div_name) VALUES (%s)",
> GetSQLValueString($_POST['div_name'], "text"));
>
> mysql_select_db($database_testadmin, $testadmin);
> $Result1 = mysql_query($insertSQL, $testadmin) or die(mysql_error());
> }
> ?>
> <form id="addDiv" name="addDiv" method="POST" action="<?php echo
> $editFormAction; ?>">
> <label for="div_name">Name:</label>
> <br />
> <input type="text" name="div_name" id="div_name" />
> <br /><br />
> <input type="submit" name="submit" id="submit" value="Add entry" />
> <input name="MM_insert" type="hidden" id="MM_insert" value="addDiv" />
> </form>
Line 51 in "add_div.inc.php" is the last line shown above - </form> -
and there is no whitespace after the closing >.
Line 44 in "update_grp.inc.php" is the header redirect shown above.
What could be the problem?
TIA
Brett
I have checked for and eliminated all whitespace in my php include files
and still I'm getting the error:
> Warning: Cannot modify header information - headers already sent by
> (output started at
> /Users/brett/vhosts/modules/admin/Products/add_div.inc.php:51)
> in /Users/brett/vhosts/modules/admin/Products/update_grp.inc.php on
> line 44
After updating a table record, I am trying to redirect to a page
containing accordion panels populated with table LIST pages. Here is my
redirect:
>
> if ($Result1) {
> header('Location: http://' . $_SERVER['HTTP_HOST'] .
> dirname($_SERVER['PHP_SELF']) .
> '/admin.php?content=Products/seeSelections');
> exit;
> }
I have looked at the include file listed in the error message and can
find no problem. Here is the code:
> <?php
> if (!function_exists("GetSQLValueString")) {
> function GetSQLValueString($theValue, $theType, $theDefinedValue = "",
> $theNotDefinedValue = "")
> {
> $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) :
> $theValue;
>
> $theValue = function_exists("mysql_real_escape_string") ?
> mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
>
> switch ($theType) {
> case "text":
> $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
> break;
> case "long":
> case "int":
> $theValue = ($theValue != "") ? intval($theValue) : "NULL";
> break;
> case "double":
> $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'"
> : "NULL";
> break;
> case "date":
> $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
> break;
> case "defined":
> $theValue = ($theValue != "") ? $theDefinedValue :
> $theNotDefinedValue;
> break;
> }
> return $theValue;
> }
> }
>
> $editFormAction = $_SERVER['PHP_SELF'];
> if (isset($_SERVER['QUERY_STRING'])) {
> $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
> }
>
> if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "addDiv")) {
> $insertSQL = sprintf("INSERT INTO divisions (div_name) VALUES (%s)",
> GetSQLValueString($_POST['div_name'], "text"));
>
> mysql_select_db($database_testadmin, $testadmin);
> $Result1 = mysql_query($insertSQL, $testadmin) or die(mysql_error());
> }
> ?>
> <form id="addDiv" name="addDiv" method="POST" action="<?php echo
> $editFormAction; ?>">
> <label for="div_name">Name:</label>
> <br />
> <input type="text" name="div_name" id="div_name" />
> <br /><br />
> <input type="submit" name="submit" id="submit" value="Add entry" />
> <input name="MM_insert" type="hidden" id="MM_insert" value="addDiv" />
> </form>
Line 51 in "add_div.inc.php" is the last line shown above - </form> -
and there is no whitespace after the closing >.
Line 44 in "update_grp.inc.php" is the header redirect shown above.
What could be the problem?
TIA
Brett
