Jump to content

Help with Code


Canman2005

Recommended Posts

Hi all

 

I have a simple shopping cart which when you add an item to the cart, the following code is run;

 

switch ($action) {
case 'add':
if ($cart)
{
$cart .= ','.$_REQUEST['id'];
header("Location: cart.html");
exit;
}
else
{
$cart = $_REQUEST['id'];
header("Location: cart.html");
exit;
}
break;

 

this has worked fine on my local web server, but when I upload it to the website server I run into some issues.

 

Firstly the above code doesn't work and no items are added, but if I remove

 

header("Location: cart.html");
exit;

 

then the code does run ok, the problem is that if it doesn't do a "header("Location")" then I still have

 

?action=add&id=2

 

showing in the URL, therefore if the page is reloaded, the quantity of that item increases by 1.

 

Does anyone know why a

 

header("Location: cart.html");

 

is stopping?

 

One thing I did notice was that "register_globals" is turned off, I found if I add

 

register_globals = on

 

to a php.ini file, the site runs fine.

 

Can anyone help?

 

Thanks

Link to comment
Share on other sites

Hmm, that code should run fine and register globals shouldn't affect it.

 

Try some debugging;

 

do this before the switch :

print_r($_GET);

print_r($_POST);

 

try the header() function before the switch to see if the header function actually works at all.

 

Any other ways you can think of debugging try also and give us your results.

 

-CB-

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.