PHP Novice... double header errors...

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
don_assi
Forum Newbie
Posts: 16
Joined: Tue Dec 03, 2002 7:40 am

PHP Novice... double header errors...

Post by don_assi »

Hi Guys,
I'm pretty new to all this PHP... and would appreciate it if anyone could help...
I'm getting the following error:
Warning: Cannot add header information - headers already sent by (output started at /home/gassi01/public_www/Cart/addCart.php:6) in /home/gassi01/public_www/Cart/addCart.php on line 14

When I run the below script:

Code: Select all

<?
require("Cart.php");
DBinfo();
Root();
mysql_connect("$DBHost","$DBUser","$DBPass");
mysql_select_db($DBName);
mysql_query("INSERT INTO CartItems VALUES
('$UID','$ItemID','$ItemQuantity','$Date','$CartItemsID')");
Header("Location: $Relative/viewCart.php?UID=$UID");
?>
The cart.php file that it links through to in order to access the DB is:

Code: Select all

<?
/* Replace these variables with information about your company */
$Company ="donassi co";
$Address1="555 Any St.";
$Address2="PO Box 3";
$City    ="London";
$State   ="UK";
$Zip     ="BR7 6EZ";
$Phone   ="+44 077 590 13806";
$Web     ="http://www.yoursite.com/";
$Email   ="don_assi@postmaster.co.uk";
$NoShipping = "Shipping Extra";
function Brand() &#123;
global $Company,$Address1,$Address2,$City,$State,$Zip,$Phone,$Web,$Email,$NoShipping;
&#125;

/* Replace these variables with information for connecting to your
database server */
$DBHost="hermes";
$DBUser="gassi01";
$DBPass="Capone77";
$DBName="gassi01db";
function DBInfo() &#123;
global $DBHost,$DBUser,$DBPass,$DBName;
&#125;

/* Replace these variables with the absolute and relative paths to your
MyCart scripts */
$WebRoot="home/gassi01/public_www/Cart";
$Relative="/~gassi01/Cart";
$WebHost="hermes.dcs.bbk.ac.uk";
function Root() &#123;
global $WebRoot,$Relative,$WebHost;
&#125;

function redFont($font,$text) &#123;
echo "<FONT FACE="$font" COLOR="red">$text</FONT>";
&#125;

function blueFont($font,$text) &#123;
echo "<FONT FACE="$font" COLOR="blue">$text</FONT>";
&#125;

function colorFont($color,$font,$text) &#123;
echo "<FONT FACE="$font" COLOR="$color">$text</FONT>";
&#125;

function fontFace($font,$text) &#123;
echo "<FONT FACE="$font">$text</FONT>";
&#125;

function fontSize($size,$color,$font,$text) &#123;
echo "<FONT FACE="$font" COLOR="$color" SIZE="$size">$text</FONT>";
&#125;

function commonHeader($Company,$title) &#123;
echo "<HTML><TITLE>$Company Shopping Cart - $title</TITLE><BODY BGCOLOR="#FFFFFF">";
&#125;

function receiptHeader($Company,$title) &#123;
echo "<HTML><TITLE>$Company Receipt - $title</TITLE><BODY BGCOLOR="#FFFFFF">";
&#125;

function commonFooter($Relative,$UID) &#123;
echo "<center><br><br><hr width="70%"><br>";
echo "<b><a href="$Relative/checkout.php?UID=$UID">Go To The Check Out Stand</a></b><br><br>";
echo "<b><a href="$Relative/viewCart.php?UID=$UID">View The Contents Of Your Cart</a></b><br><br>";
fontFace("Arial","<a href="$Relative/index.php?UID=$UID">Our Catalog</a>");
fontFace("Arial"," | <a href="/">Home</a>");
echo "<br><br></center></BODY></HTML>";
&#125;

function adminFooter($Relative) &#123;
echo "<center><br><br><hr width="70%"><br>";
fontFace("Arial"," | <a href="$Relative">Our Catalog</a>");
fontFace("Arial"," | <a href="$Relative/admin/">Shopping Cart Admin</a>");
fontFace("Arial"," | <a href="http://modems.rosenet.net/mysql/">MySQL Utilities</a>");
fontFace("Arial"," | <a href="http://www.rosenet.net/">Rosenet</a>");
echo "<br><br></center></BODY></HTML>";
&#125;

function receiptFooter($Company) &#123;
echo "<br><br><center>";
fontFace("Arial","Thank you for ordering from <b>$Company</b>");
echo "</center><br><br>";
&#125;

?>
So it seems that the information is being sent twice... is there anything wrong with the script?
User avatar
Traduim
Forum Newbie
Posts: 11
Joined: Tue Dec 10, 2002 4:21 am
Location: Catalunya

Post by Traduim »

If you look Cart.php you'll see there are some echoes in it.

Headers can only be sent when nothing else have been sent to client's browser.

If you want to use header(), you must get rid of all echoes and other printable stuff (including white spaces and line feeds out of <? ?>)
don_assi
Forum Newbie
Posts: 16
Joined: Tue Dec 03, 2002 7:40 am

Header Errors

Post by don_assi »

Thanks,

But I'm not sure how I am going to get around this... how would I be able to link to the cart.php (the main file) through the require statement and at the same time link through to the next page (currently through the 'Header' statement?

Thanks
don_assi
User avatar
nathus
Forum Commoner
Posts: 49
Joined: Thu Dec 12, 2002 6:23 pm

Post by nathus »

Don't think its the echo statements that are giving you the problem, as the functions that contain them aren't called. However, I have a question as to what the DBInfo, Brand, and Root functions are for?
User avatar
nathus
Forum Commoner
Posts: 49
Joined: Thu Dec 12, 2002 6:23 pm

Post by nathus »

i played around with the code a bit, and got it to work I think. there's a space after the ?> in cart.php thats messing it up. (at least thats what fixed it for me).
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

Code: Select all

function Brand() &#123; 
global $Company,$Address1,$Address2,$City,$State,$Zip,$Phone,$Web,$Email,$NoShipping; 
&#125;
and

Code: Select all

function DBInfo() &#123; 
global $DBHost,$DBUser,$DBPass,$DBName; 
&#125;
and

Code: Select all

function Root() &#123; 
global $WebRoot,$Relative,$WebHost; 
&#125;
are unecissary, when you include a file, all the variables defined will merge into the current scope, there is no need to do anything like that.
Post Reply