GET method issue

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dlna
Forum Newbie
Posts: 3
Joined: Tue Dec 01, 2009 4:53 am

GET method issue

Post by dlna »

Hi,
I'm new to PHP and in order to learn the language and the concepts I'm working on a e-commerce website with a shopping cart, etc.
In this site I have items, when an item is clicked, the id of the item is sent via the GET method to the shopping cart page. Using this id i add the item to the shopping cart(table) and it works fine.

The issue is; if the user clicks the refresh button, the item is added again to the shopping cart. Do you think that disabling the refresh button or F5 button is a good option? what must i do to prevent the user from adding the item to the shopping cart when the page is refreshed?
In forms I've noticed that "(isset($_POST['Submit'])){}" is helpful but for the GET method this doesn't work accordingly.

Your help is appreciated.
User avatar
mrvijayakumar
Forum Commoner
Posts: 58
Joined: Tue Aug 18, 2009 12:39 am
Location: Chennai city, India
Contact:

Re: GET method issue

Post by mrvijayakumar »

Hi,

While u submit the form? Form values will submit again & again. So, better to pass the value to page like below,

Try this,
Ex - http://ursite.com/cart.php?total=1&rs=25$.
dlna
Forum Newbie
Posts: 3
Joined: Tue Dec 01, 2009 4:53 am

Re: GET method issue

Post by dlna »

I'm sorry I didn't get you. There's no form involved in the shoppingcart page.

this is the link, given in the items page.
<a href="do_shoppingcart.php?id=<?php echo "$itm_id"; ?>">

thanks,
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: GET method issue

Post by AbraCadaver »

I would probably set a session var when entering the cart, clear the var on other pages, and then check for that var when in the cart:

Code: Select all

if(!isset($_SESSION['in_cart'])) {
    $_SESSION['in_cart'] = 1;
    // update cart
}
-Shawn
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
dlna
Forum Newbie
Posts: 3
Joined: Tue Dec 01, 2009 4:53 am

Re: GET method issue

Post by dlna »

Thank so much, it worked! :D
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: GET method issue

Post by AbraCadaver »

dlna wrote:Thank so much, it worked! :D
Don't forget to unset($_SESSION['in_cart']) in other pages.

You might want to put the whole thing into a header or other include that is included in every page, with logic to work out if they're in the cart or not and set/unset accordingly.

-Shawn
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply