Page 1 of 1

addtocart to integrate Storefront

Posted: Tue Apr 13, 2004 7:24 am
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

Posted: Tue Apr 13, 2004 8:19 am
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.

Posted: Tue Apr 13, 2004 8:50 am
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

Posted: Sat Apr 17, 2004 5:21 am
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.