addtocart to integrate Storefront

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
jamessirleaf
Forum Newbie
Posts: 8
Joined: Tue Apr 13, 2004 7:24 am
Location: Reading, UK

addtocart to integrate Storefront

Post by jamessirleaf »

I am working with windows 2000 server using xitami2.5 webserver and php 4.5. using sams -teach yourself php, mysql and apache, i have tried to do addtocart to integrate my storefront with the cart mechanism....
the script requires, i.e. p.415,

$addtocart = "isert into store_shoppertrack values ('','$PHPSESSID','$_POST[sel_item_id]','$_POST[sel_item_qty]','now())";
mysql_query($addtocart);

header("Location:showcart.php");
exit;

I get error message warning: cannot modify header information-
headers already sent by (output started at c:\xitami-25\app\webpages\addtocart.php:6) etc.

Basically, table store_shoppertrack is already updated with session information but why this behavior?

I need to be redirected to load the page showcart.php.

Thanks.

James
TheBentinel.com
Forum Contributor
Posts: 282
Joined: Wed Mar 10, 2004 1:52 pm
Location: Columbus, Ohio

Post by TheBentinel.com »

The header can only be sent prior to any other page text. So you need to either remove all the text above that header call (By text, I mean stuff that would show up if the user chose "view source" in their browser), move the header call up above that text, or use a javascript redirect.

The javascript redirect is not recommended, since not all users have javascript enabled.
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

TheBentinel.com wrote:The header can only be sent prior to any other page text. So you need to either remove all the text above that header call (By text, I mean stuff that would show up if the user chose "view source" in their browser), move the header call up above that text, or use a javascript redirect.
this is absolutely true

what i usually do instead of printing out the error directly to the user is something like this:

Code: Select all

// just an idea
// say i wanted to print this
if ($value == "1")
{
$printtext = "mal";
}
else
{
$printtext = "lam";
}
header ("Location: ../index.php");
you can then echo the variable on the next page with no errors

this is only in desperate measures and reorganising your script would negate the use for this
jamessirleaf
Forum Newbie
Posts: 8
Joined: Tue Apr 13, 2004 7:24 am
Location: Reading, UK

Post by jamessirleaf »

Hello,

I had pasted a response earlier, but just can't find it now. Many thanks for the assistance. Actually, I couldn't locate any text files that would hinder this redirection. In any event, I decided to place a small flash button link at the bottom of the page. I know it poses more user direct involvement.

I didn't use javascript because of the obvious useability issues when web browsers are considered.
Post Reply