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
https://forums.phpfreaks.com/topic/185796-help-with-code/
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
https://forums.phpfreaks.com/topic/185796-help-with-code/#findComment-981063
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.