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.
GET method issue
Moderator: General Moderators
- mrvijayakumar
- Forum Commoner
- Posts: 58
- Joined: Tue Aug 18, 2009 12:39 am
- Location: Chennai city, India
- Contact:
Re: GET method issue
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$.
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$.
Re: GET method issue
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,
this is the link, given in the items page.
<a href="do_shoppingcart.php?id=<?php echo "$itm_id"; ?>">
thanks,
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: GET method issue
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:
-Shawn
Code: Select all
if(!isset($_SESSION['in_cart'])) {
$_SESSION['in_cart'] = 1;
// update cart
}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.
Re: GET method issue
Thank so much, it worked! 
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: GET method issue
Don't forget to unset($_SESSION['in_cart']) in other pages.dlna wrote:Thank so much, it worked!
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.