Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

php emptying $_post

Engaged ,
Sep 28, 2009 Sep 28, 2009

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

TOPICS
Server side applications
719
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 28, 2009 Sep 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Sep 28, 2009 Sep 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 28, 2009 Sep 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Sep 28, 2009 Sep 28, 2009

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 28, 2009 Sep 28, 2009

In a word, no.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Sep 28, 2009 Sep 28, 2009
LATEST

ok mate. cheers. i think it's a browser problem, not a programming problem. i don't get it in firefox.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines