Copy link to clipboard
Copied
hello
i am having a play trying to create a simple shopping checkout, using code, no specialist software.
everything is working fine, except when i add or delete an item, and refresh the page, the add/delete is being repeated. which is obviousley bad.
i've tried unsetting the $_posts and emptying any variable being used, but this isn't doing the trick. any ideas....p.s, i'm trying to get the delete item code to work first, so have not altered my add item code.
to test the page, go to http://www.malcmabe.co.uk/custdetails.php
create a username and password using the top columns.click on search for items, and type 'nike' into the search box. click on one of the products and then add x amount to the basket.
if you then f5 refresh, the process is repeated.
in the item code column, type in the item code of the product you have chosen, and choose a quantity to delete. this will delete fine, but if you f5 refresh, another deletion takes place.
here is the code for deletion process:
if(isset($_POST['delitem']))
{
$code = $_POST['itemcode'];
$quant = $_POST['delquant'];
print("<br/> ".$code." ".$quant);
mysql_query("delete from checkout where itemid = '$code' and username = '$username' LIMIT $quant ");
unset($_POST['delitem']);
unset($_POST['itemcode']);
unset($_POST['delquant']);
$code = null;
$quant = null;
}
i would appreciate any help. thanks
Copy link to clipboard
Copied
Refreshing a page that sends POST data automatically resends the contents of the $_POST array. To add or delete items, you need to submit the form again. That's the only way the new data can be sent.
Copy link to clipboard
Copied
thanks david
but what i'm getting at, is that if the user adds or deletes an item, and then refreshes for whatever reason, than another item will be added or deleted.
basically, i want no post items to be sent when they refresh the page.
the only time i want data to be sent is when they press a button.
Copy link to clipboard
Copied
That's the way that browsers work. Refreshing the page resends the data. Normally, the browser will display a warning to that effect.
To the best of my knowledge, there is no way around this.
Copy link to clipboard
Copied
ok mate, thanks
just a quick one, when i click on refresh, and press cancel on the warning, i get a message saying my page has expired. the only way to reload is to click on retry, which would repost the $_post variables.
is there a way around that?
malcolm
Copy link to clipboard
Copied
In a word, no.
Copy link to clipboard
Copied
ok mate. cheers. i think it's a browser problem, not a programming problem. i don't get it in firefox.