![]() |
![]() |
||||||
|
|||||||
| Tags: |
![]() |
|
|||
|
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 |
| Sponsored Links |
|
|||
|
Brett wrote:
> 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 The error message says that output was started on line 44 of update_grp.inc.php. That's where you should look for the problem. -- David Powers, Adobe Community Expert Author, "The Essential Guide to Dreamweaver CS3" (friends of ED) Author, "PHP Solutions" (friends of ED) http://foundationphp.com/ |
|
|||
|
Brett wrote:
> 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 The error message says that output was started on line 44 of update_grp.inc.php. That's where you should look for the problem. -- David Powers, Adobe Community Expert Author, "The Essential Guide to Dreamweaver CS3" (friends of ED) Author, "PHP Solutions" (friends of ED) http://foundationphp.com/ |
|
|||
|
Thanks David, I looked at line 44:
> if ($Result1) { > header('Location: http://' . $_SERVER['HTTP_HOST'] . > dirname($_SERVER['PHP_SELF']) . > '/admin.php?content=Products/seeSelections'); > exit; > } but I don't see where the problem is. Line 44 starts with: header('Location: ...etc. as shown above. I have used this code on many other pages and it works fine, why not here? Best, Brett |
|
|||
|
Thanks David, I looked at line 44:
> if ($Result1) { > header('Location: http://' . $_SERVER['HTTP_HOST'] . > dirname($_SERVER['PHP_SELF']) . > '/admin.php?content=Products/seeSelections'); > exit; > } but I don't see where the problem is. Line 44 starts with: header('Location: ...etc. as shown above. I have used this code on many other pages and it works fine, why not here? Best, Brett |
|
|||
|
Brett wrote:
> but I don't see where the problem is. Line 44 starts with: > header('Location: ...etc. as shown above. I have used this code on many > other pages and it works fine, why not here? As always with PHP error messages, you need to start working backwards from that point. One thing I would suggest looking for is the use of the Byte Order Mark. In each page, select Modify > Page Properties. In the Title/Encoding section, make sure that Include Unicode Signature (BOM) is deselected. -- David Powers, Adobe Community Expert Author, "The Essential Guide to Dreamweaver CS3" (friends of ED) Author, "PHP Solutions" (friends of ED) http://foundationphp.com/ |
|
|||
|
David,
I found the solution to my problem. I needed to use output buffering to prevent headers being sent. What I did was place ob_start() at the beginning of the page with all of the accordion elements, and ob_end_flush() at the very end. Now when I edit a record in one accordion panel and click update, I'm redirected to the same page with the default settings for all panels and the record shows the update. Whew! That's a relief! As always, thanks for taking the time to help. Best, Brett |
|
|||
|
David,
I found the solution to my problem. I needed to use output buffering to prevent headers being sent. What I did was place ob_start() at the beginning of the page with all of the accordion elements, and ob_end_flush() at the very end. Now when I edit a record in one accordion panel and click update, I'm redirected to the same page with the default settings for all panels and the record shows the update. Whew! That's a relief! As always, thanks for taking the time to help. Best, Brett |
|
|||
|
..oO(Brett)
>I found the solution to my problem. I needed to use output buffering to >prevent headers being sent. No. It's an ugly workaround, but doesn't fix the real problem. You should re-order your code so that all tests and calculations happen before the first line of output. Micha |
|
|||
|
..oO(Brett)
>I found the solution to my problem. I needed to use output buffering to >prevent headers being sent. No. It's an ugly workaround, but doesn't fix the real problem. You should re-order your code so that all tests and calculations happen before the first line of output. Micha |
![]() |
| Thread Tools | |
| Display Modes | |
|
|
- Contact Us
-|-
Adobe Dreamweaver Forums -|-
Archive -|-
Top -|-Rules/Disclaimer-|-Help/Support-|-Advertise