Page 1 of 1

Submit button to shopping cart generates a duplicate page

Posted: Sun Aug 02, 2015 11:57 pm
by SpokaneDude
I have a several pages with small forms on them where I have a button in each which does a submit to a shopping cart. The problem is whenever I click on the Submit button, it generates a new page which is a duplicate of the one where I just came from. This is the code for the Page HTML (before the </body> tag). When I had only one 'product' page, it worked fine; after I added content to the remainder of the 'product' pages, it displays this duplicate page. BTW, on the duplicate page, it displays the echo of the 'item-count' correctly.

Code: Select all

<?php

session_start();

define("PRODUCTCODE", 0);
define("PRODUCTNAME", 1);
define("QUANTITY", 2);
define("PRICE", 3);

	$action = isset($_POST['action']) ? $_POST['action'] : '';

  if (isset($_POST['productcode']))  {
      AddToCart();
   }

function AddToCart()  {
   $cart = isset($_SESSION['cart']) ? $_SESSION['cart'] : '';

   $itemcount = isset($_SESSION['itemcount']) ? $_SESSION['itemcount'] : 0;
   $cart[PRODUCTCODE][$itemcount] = $_POST['productcode'];
   $cart[PRODUCTNAME][$itemcount] = $_POST['productname'];
   $cart[QUANTITY][$itemcount] = intval($_POST['quantity']);
   $cart[PRICE][$itemcount] = $_POST['price'];
   $itemcount = $itemcount + 1;

   $_SESSION['cart'] = $cart;
   $_SESSION['itemcount'] = $itemcount;
echo "addToCart-itemcount: ".$itemcount;
}

?>
Any ideas what's causing this anomaly?

Re: Submit button to shopping cart generates a duplicate pag

Posted: Mon Aug 03, 2015 2:35 am
by mexman
Did you enter a success page?
Are the forms on the same page or on different pages?

Michael

Re: Submit button to shopping cart generates a duplicate pag

Posted: Mon Aug 03, 2015 3:44 am
by SpokaneDude
This is for eCommerce, so there are several forms are on each page; there are about 9 pages, one for each category (flowers, children, wildlife, etc). And yes, there is a success page (viewCart.php) which the user goes to by clicking on the View Cart menu.

Re: Submit button to shopping cart generates a duplicate pag

Posted: Mon Aug 03, 2015 6:41 am
by Pablo
Although I cannot help you with custom coding. It looks like you have set a 'target' in the form properties, so a new page will be opened on submit.

Re: Submit button to shopping cart generates a duplicate pag

Posted: Mon Aug 03, 2015 12:39 pm
by SpokaneDude
Unbelievable! That was it! Thank you so much... I really appreciate it.. :D