cannot seem to use both include nad header functions togethe

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
reiqwan
Forum Commoner
Posts: 25
Joined: Fri Jan 07, 2005 2:27 am

cannot seem to use both include nad header functions togethe

Post by reiqwan »

Hi all;

This is a real basic one; the problem seems to be that I cannot use the include and header function together.

When I use the header function to send my clients to the page called main.php (by the way main.php has three include files and one of them which is a variable defined from the page before) I get the following error:

Warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\Apache Group\Apache2\htdocs\respondnow\main.php:8) in C:\Program Files\Apache Group\Apache2\htdocs\respondnow\editevent.php on line 56

Now i know that Im getting this error because of the include and header items being used together I just cant seem to sort it out or find some other information regarding how to fix or work around it.?????

THanks all, any help is appreciated.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Warning: Cannot add header information

a lovely tutorial on what's wrong and how to fix it, written by our very own people.

please search next time, thanks. :mrgreen:
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

If you're putting your include() somewhere before the header() then you'll get that error.

header() cannot be used anywhere on a page after anything has been sent for output (that includes whitespace such as line breaks).

Check if your header is being sent anywhere after such includes or printed content in the whole scale of things and then you should see it. :wink:
User avatar
reiqwan
Forum Commoner
Posts: 25
Joined: Fri Jan 07, 2005 2:27 am

my includes are on another page

Post by reiqwan »

thanks feyd for the quick response but when i use the buffer output cleaner it tells me that there is: No buffer to delete or flush

Now I'm not to sure if i used it correctly, but i just placed it at the end of my php statement(it seems like it's pretty easy to use)



d11wtq, i have included the pages php code that i'm referencing so you can see what I'm talking about this is refenced when the btton is pushed to execute the php code:

Code: Select all

<?php
<?php require_once('Connections/RespondNow.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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"] == "form1")) {
  $updateSQL = sprintf("UPDATE events SET Name=%s, Adress=%s, Venue=%s, `Date`=%s, `Time`=%s, Description=%s, TemplateType=%s, MaxSeats=%s, Sponsor=%s, `Map`=%s WHERE ID=%s",
                       GetSQLValueString($_POST['txtEventName'], "text"),
                       GetSQLValueString($_POST['txtAdress'], "text"),
                       GetSQLValueString($_POST['txtVenue'], "text"),
                       GetSQLValueString($_POST['txtDate'], "text"),
                       GetSQLValueString($_POST['txtTime'], "text"),
                       GetSQLValueString($_POST['txtInviteCopy'], "text"),
                       GetSQLValueString($_POST['ddlEventType'], "text"),
                       GetSQLValueString($_POST['txtMaxReg'], "text"),
                       GetSQLValueString($_POST['txtSponsor'], "text"),
                       GetSQLValueString($_POST['txtMap'], "text"),
                       GetSQLValueString($_POST['hiddenRecID'], "int"));

  mysql_select_db($database_RespondNow, $RespondNow);
  $Result1 = mysql_query($updateSQL, $RespondNow) or die(mysql_error());
 
 /* $updateGoTo = "";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
  }*/
  header("Location: main.php");
  

}
?>
and here's the error i get


Warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\Apache Group\Apache2\htdocs\respondnow\main.php:8) in C:\Program Files\Apache Group\Apache2\htdocs\respondnow\editevent.php on line 55


the thing is when i use framesets to send the clients around I dont get a problem with the header function; as soon as I started using main.php which has the include statements

the php code for main.php is as follows:

Code: Select all

<?php
include ("top.htm");
include ("menu.php"); 
include ("$type.php"); 
?>

like i said when i use this code i get the header function im convinced its got to do with me using include nad headers simultaneously

thanks again all


feyd | Help us, help you. Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Your include contains printed htm pages. This is blocking your header.

EDIT: Sorry my bad.... can I see the code in the page you call for require_once() please? This will be where the problem lies
User avatar
reiqwan
Forum Commoner
Posts: 25
Joined: Fri Jan 07, 2005 2:27 am

this is all the code

Post by reiqwan »

this is all the code from top to bottom i've made sure that theres not a single space left anywhere

Code: Select all

<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_RespondNow = "localhost";
$database_RespondNow = "respondnow";
$username_RespondNow = "root";
$password_RespondNow = "pass";
$RespondNow = mysql_pconnect($hostname_RespondNow, $username_RespondNow, $password_RespondNow) or trigger_error(mysql_error(),E_USER_ERROR); 
?>

feyd | Help us, help you. Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
AGISB
Forum Contributor
Posts: 422
Joined: Fri Jul 09, 2004 1:23 am

Post by AGISB »

I take it you have no space or empty line before <?php in either the include file
or the main file?

A reason can be that you database call yields an error which would be an output as well.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Aaahh... good point. I'd go with the database query suggestion raised by AGISB. Seems a logical culprit
Post Reply