![]() |
![]() |
||||||
|
|||||||
| Tags: |
![]() |
|
|||
|
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/ |
| Sponsored Links |
|
|||
|
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 |
|
|||
|
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 |
|
|||
|
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/ |
|
|||
|
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/ |
|
|||
|
>
> 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 |
|
|||
|
>
> 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 |
|
|||
|
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 |
![]() |
| Thread Tools | |
| Display Modes | |
|
|
- Contact Us
-|-
Adobe Dreamweaver Forums -|-
Archive -|-
Top -|-Rules/Disclaimer-|-Help/Support-|-Advertise