Submit button to shopping cart generates a duplicate page

Issues related to forms.
Post Reply
SpokaneDude
Posts: 46
Joined: Tue Oct 23, 2012 9:47 pm

Submit button to shopping cart generates a duplicate page

Post by SpokaneDude » Sun Aug 02, 2015 11:57 pm

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?

mexman
Posts: 495
Joined: Mon Feb 11, 2013 11:33 am
Location: Puebla/Mexico

Re: Submit button to shopping cart generates a duplicate pag

Post by mexman » Mon Aug 03, 2015 2:35 am

Did you enter a success page?
Are the forms on the same page or on different pages?

Michael

SpokaneDude
Posts: 46
Joined: Tue Oct 23, 2012 9:47 pm

Re: Submit button to shopping cart generates a duplicate pag

Post by SpokaneDude » Mon Aug 03, 2015 3:44 am

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.

User avatar
Pablo
Site Admin
Posts: 2637
Joined: Mon Feb 13, 2006 7:00 am
Location: Europe
Contact:

Re: Submit button to shopping cart generates a duplicate pag

Post by Pablo » Mon Aug 03, 2015 6:41 am

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.

SpokaneDude
Posts: 46
Joined: Tue Oct 23, 2012 9:47 pm

Re: Submit button to shopping cart generates a duplicate pag

Post by SpokaneDude » Mon Aug 03, 2015 12:39 pm

Unbelievable! That was it! Thank you so much... I really appreciate it.. :D

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest