Adobe Dreamweaver Forums



Last 10 THreads :         Seeking advise on flv in Captivate 3 (Last Post : 9060 - Replies : 0 - Views : 1 )           »          Global variables (Last Post : jfb00 - Replies : 0 - Views : 1 )           »          catching errors from remotely invoked processes (Last Post : Cr99 - Replies : 4 - Views : 5 )           »          Dreamweaver CS4 Beta Uninstaller? (Last Post : _Burn_ - Replies : 0 - Views : 1 )           »          Div or iFrame resize depending on content. (Last Post : Nancy O - Replies : 5 - Views : 7 )           »          Flex and ColdFusion web services (Last Post : jfb00 - Replies : 1 - Views : 2 )           »          Advanced datagrid using Remote Objects (Last Post : rkcy - Replies : 5 - Views : 6 )           »          Flickering tooltip in bottom right corner (Last Post : aperitech - Replies : 4 - Views : 5 )           »          Change Font on Buttons (Last Post : CJ KY - Replies : 0 - Views : 1 )           »          RoboHelp & Knowledge Bases (Last Post : lmarden - Replies : 2 - Views : 3 )           »         


Home Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
User Info Statistics
Go Back   Adobe Dreamweaver Forums > Dreamweaver: Main > Dreamweaver Application Development
 
Tags:



Reply
  #11 (permalink)  
Old 10-01-2008, 01:49 PM
David Powers
 
Posts: n/a
Diggs:
Default Re: Dreaded "headers already sent" error

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/
Reply With Quote
Sponsored Links
  #12 (permalink)  
Old 10-01-2008, 01:49 PM
Brett
 
Posts: n/a
Diggs:
Default Re: Dreaded "headers already sent" error

David,

I'm completely stumped. I've looked at the code for
"update_grp.inc.php" and I can see no place that the header has been
sent before. Here is the complete code for that page:

> <?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_update"])) && ($_POST["MM_update"] == "editGrp")) {
> $updateSQL = sprintf("UPDATE grp SET grp_name=%s WHERE grp_id=%s",
> GetSQLValueString($_POST['grp_name'], "text"),
> GetSQLValueString($_POST['grp_id'], "int"));
>
> mysql_select_db($database_testadmin, $testadmin);
> $Result1 = mysql_query($updateSQL, $testadmin) or die(mysql_error());
>
> if ($Result1) {
> header('Location: http://' . $_SERVER['HTTP_HOST'] .
> dirname($_SERVER['PHP_SELF']) .
> '/admin.php?content=Products/seeSelections');
> exit;
> }
> }
>
> $colname_getGrp = "-1";
> if (isset($_GET['grp_id'])) {
> $colname_getGrp = $_GET['grp_id'];
> }
> mysql_select_db($database_testadmin, $testadmin);
> $query_getGrp = sprintf("SELECT * FROM grp WHERE grp_id = %s",
> GetSQLValueString($colname_getGrp, "int"));
> $getGrp = mysql_query($query_getGrp, $testadmin) or die(mysql_error());
> $row_getGrp = mysql_fetch_assoc($getGrp);
> $totalRows_getGrp = mysql_num_rows($getGrp);
>
> ?>
> <form action="<?php echo $editFormAction; ?>" id="editGrp"
> name="editGrp" method="POST">
> <label for="grp_name">Name:</label>
> <br />
> <input name="grp_name" type="text" id="grp_name" value="<?php echo
> htmlentities($row_getGrp['grp_name'], ENT_COMPAT, 'UTF-8'); ?>" />
> <br /><br />
> <input type="submit" name="submit" id="submit" value="Update entry" />
> <input name="grp_id" type="hidden" id="grp_id" value="<?php echo
> $row_getGrp['grp_id']; ?>" />
> <input type="hidden" name="MM_update" value="editGrp" />
> </form>
>
> <?php
> mysql_free_result($getGrp);
> ?>

As I mentioned before, line 44 starts with "header(Location: ...etc.)
Can you spot the problem? I checked the Page properties on all pages
which are included and none have the BOM selected. Any other thoughts?

Many thanks for your help.

Brett
Reply With Quote


  #13 (permalink)  
Old 10-01-2008, 01:49 PM
Brett
 
Posts: n/a
Diggs:
Default Re: Dreaded "headers already sent" error

David,

I'm completely stumped. I've looked at the code for
"update_grp.inc.php" and I can see no place that the header has been
sent before. Here is the complete code for that page:

> <?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_update"])) && ($_POST["MM_update"] == "editGrp")) {
> $updateSQL = sprintf("UPDATE grp SET grp_name=%s WHERE grp_id=%s",
> GetSQLValueString($_POST['grp_name'], "text"),
> GetSQLValueString($_POST['grp_id'], "int"));
>
> mysql_select_db($database_testadmin, $testadmin);
> $Result1 = mysql_query($updateSQL, $testadmin) or die(mysql_error());
>
> if ($Result1) {
> header('Location: http://' . $_SERVER['HTTP_HOST'] .
> dirname($_SERVER['PHP_SELF']) .
> '/admin.php?content=Products/seeSelections');
> exit;
> }
> }
>
> $colname_getGrp = "-1";
> if (isset($_GET['grp_id'])) {
> $colname_getGrp = $_GET['grp_id'];
> }
> mysql_select_db($database_testadmin, $testadmin);
> $query_getGrp = sprintf("SELECT * FROM grp WHERE grp_id = %s",
> GetSQLValueString($colname_getGrp, "int"));
> $getGrp = mysql_query($query_getGrp, $testadmin) or die(mysql_error());
> $row_getGrp = mysql_fetch_assoc($getGrp);
> $totalRows_getGrp = mysql_num_rows($getGrp);
>
> ?>
> <form action="<?php echo $editFormAction; ?>" id="editGrp"
> name="editGrp" method="POST">
> <label for="grp_name">Name:</label>
> <br />
> <input name="grp_name" type="text" id="grp_name" value="<?php echo
> htmlentities($row_getGrp['grp_name'], ENT_COMPAT, 'UTF-8'); ?>" />
> <br /><br />
> <input type="submit" name="submit" id="submit" value="Update entry" />
> <input name="grp_id" type="hidden" id="grp_id" value="<?php echo
> $row_getGrp['grp_id']; ?>" />
> <input type="hidden" name="MM_update" value="editGrp" />
> </form>
>
> <?php
> mysql_free_result($getGrp);
> ?>

As I mentioned before, line 44 starts with "header(Location: ...etc.)
Can you spot the problem? I checked the Page properties on all pages
which are included and none have the BOM selected. Any other thoughts?

Many thanks for your help.

Brett
Reply With Quote
  #14 (permalink)  
Old 10-01-2008, 01:49 PM
David Powers
 
Posts: n/a
Diggs:
Default Re: Dreaded "headers already sent" error

Brett wrote:
> I'm completely stumped.


The problem is here:

>> ?>
>> <form action="<?php echo $editFormAction; ?>" id="editGrp"
>> name="editGrp" method="POST">
>> <label for="grp_name">Name:</label>
>> <br />
>> <input name="grp_name" type="text" id="grp_name" value="<?php echo
>> htmlentities($row_getGrp['grp_name'], ENT_COMPAT, 'UTF-8'); ?>" />
>> <br /><br />
>> <input type="submit" name="submit" id="submit" value="Update entry" />
>> <input name="grp_id" type="hidden" id="grp_id" value="<?php echo
>> $row_getGrp['grp_id']; ?>" />
>> <input type="hidden" name="MM_update" value="editGrp" />
>> </form>


The form is HTML output. It doesn't matter that the header() function is
on line 44 ahead of this output. The reason it triggers "headers already
sent" is because the form is part of the include file. There must be no
output to the browser in an include file if you're using header() or
sessions.

--
David Powers, Adobe Community Expert
Author, "The Essential Guide to Dreamweaver CS3" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/
Reply With Quote
  #15 (permalink)  
Old 10-01-2008, 01:49 PM
David Powers
 
Posts: n/a
Diggs:
Default Re: Dreaded "headers already sent" error

Brett wrote:
> I'm completely stumped.


The problem is here:

>> ?>
>> <form action="<?php echo $editFormAction; ?>" id="editGrp"
>> name="editGrp" method="POST">
>> <label for="grp_name">Name:</label>
>> <br />
>> <input name="grp_name" type="text" id="grp_name" value="<?php echo
>> htmlentities($row_getGrp['grp_name'], ENT_COMPAT, 'UTF-8'); ?>" />
>> <br /><br />
>> <input type="submit" name="submit" id="submit" value="Update entry" />
>> <input name="grp_id" type="hidden" id="grp_id" value="<?php echo
>> $row_getGrp['grp_id']; ?>" />
>> <input type="hidden" name="MM_update" value="editGrp" />
>> </form>


The form is HTML output. It doesn't matter that the header() function is
on line 44 ahead of this output. The reason it triggers "headers already
sent" is because the form is part of the include file. There must be no
output to the browser in an include file if you're using header() or
sessions.

--
David Powers, Adobe Community Expert
Author, "The Essential Guide to Dreamweaver CS3" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/
Reply With Quote


  #16 (permalink)  
Old 10-01-2008, 01:49 PM
Brett
 
Posts: n/a
Diggs:
Default Re: Dreaded "headers already sent" error

> The reason it triggers "headers already sent" is because the form is
> part of the include file.


I began to realize that, but I didn't know what to do about it.
Reply With Quote
  #17 (permalink)  
Old 10-01-2008, 01:49 PM
Brett
 
Posts: n/a
Diggs:
Default Re: Dreaded "headers already sent" error

> The reason it triggers "headers already sent" is because the form is
> part of the include file.


I began to realize that, but I didn't know what to do about it.
Reply With Quote
  #18 (permalink)  
Old 10-01-2008, 01:49 PM
Brett
 
Posts: n/a
Diggs:
Default Re: Dreaded "headers already sent" error

>
> 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.

I thought that was the purpose of output buffering. What is the real
problem then? I thought the problem was that I couldn't redirect to my
page because I was getting the headers error.

What makes this an ugly workaround? I have 20 includes in this page,
each of which has some html, either a table or form. Are you saying
that my includes should only contain the php tests and validations, and
that all forms and tables should be in the accordion panels directly in
this page? So the dynamic data in my forms and tables need to be placed
within this page? Doesn't this defeat the purpose of using includes to
make a site more modular?

Micha, I'm not challenging your knowledge, you've probably forgotten
more than I'll ever know, but I'm trying to understand these concepts
better.

Best,

Brett


Reply With Quote


  #19 (permalink)  
Old 10-01-2008, 01:49 PM
Brett
 
Posts: n/a
Diggs:
Default Re: Dreaded "headers already sent" error

>
> 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.

I thought that was the purpose of output buffering. What is the real
problem then? I thought the problem was that I couldn't redirect to my
page because I was getting the headers error.

What makes this an ugly workaround? I have 20 includes in this page,
each of which has some html, either a table or form. Are you saying
that my includes should only contain the php tests and validations, and
that all forms and tables should be in the accordion panels directly in
this page? So the dynamic data in my forms and tables need to be placed
within this page? Doesn't this defeat the purpose of using includes to
make a site more modular?

Micha, I'm not challenging your knowledge, you've probably forgotten
more than I'll ever know, but I'm trying to understand these concepts
better.

Best,

Brett


Reply With Quote
  #20 (permalink)  
Old 10-01-2008, 01:49 PM
Brett
 
Posts: n/a
Diggs:
Default Re: Dreaded "headers already sent" error

David,

I'm beginning to think I don't understand about using the header()
function. I have read in your books and others that "Using header() or
starting a PHP session must be done before any output is sent to the
browser." Does that mean in the "sending" page not the "receiving"
page? I thought it meant the receiving page, the page to which you are
redirected. Now I'm thinking I have misunderstood this entirely.

So my question is, as I posed to Micha in this thread, how does one
construct a page like I have with 20 include files, each of which
contains html. As you may know from my post on your FOE forum "backend
blight", the page I'm trying to build has 5 Spry accordions each of
which contains 4 panels for LIST, ADD, EDIT, DELETE. My intention was
to create the individual pages for each panel and include() them in the
appropriate panel, forms, tables and all. I believed this "modular"
approach was the best and cleanest way to accomplish this. Now I'm not
sure how to go about it given my desire to use header() to redirect on
update or delete.

Also, Micha says that my solution - using ob_start() and ob_end_flush()
is an ugly workaround. I'm trying to understand why that is if it
accomplishes what is needed and functions as expected. Is this a case
of coder aesthetics and my solution is just not elegant, or is it truly
flawed?

Thanks to you and Micha for responding.

Best,

Brett
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



© Camley Interactive (camley.info) 2008 - all logos and images are copywrite their respective owners.
Proud member of the Camley Interactive Network
All times are GMT. The time now is 08:17 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
Inactive Reminders By Mished.co.uk