Skip to main content
Inspiring
September 28, 2009
Question

php emptying $_post

  • September 28, 2009
  • 1 reply
  • 779 views

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

This topic has been closed for replies.

1 reply

David_Powers
Inspiring
September 28, 2009

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.

malcster2Author
Inspiring
September 28, 2009

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.

David_Powers
Inspiring
September 28, 2009

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.