erase $_POST data after submition

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Takeshi
New php-forum User
New php-forum User
Posts: 7
Joined: Fri May 17, 2013 3:07 am

erase $_POST data after submition

Postby Takeshi » Tue Nov 12, 2013 1:39 pm

Hello everyone, can you tell me please, how can I erase data after submition? send post data to increase some value and then I reload page, it increase my number twice ... so thats the problem ... I hope it is clear .... thanks for answers

User avatar
simplypixie
php-forum Active User
php-forum Active User
Posts: 300
Joined: Sun Dec 11, 2011 12:51 am
Location: Shrewsbury, Shropshire
Contact:

Re: erase $_POST data after submition

Postby simplypixie » Thu Nov 14, 2013 12:14 am

If you want to remove all posted data you can just use

Code: Select all

unset($_POST);


If you want to just remove a specific posted variable / key, you would be more specific

Code: Select all

unset($_POST['key_name_here']);

Takeshi
New php-forum User
New php-forum User
Posts: 7
Joined: Fri May 17, 2013 3:07 am

Re: erase $_POST data after submition

Postby Takeshi » Sun Nov 17, 2013 6:08 am

Thank you, but I had found this code 'unset' before you wrote here, but the problem is I do not know how to use it. So for example this is a simple code:

Code: Select all

<?php

if(isset($_POST['abc'])){
    echo $_POST['abc'];
    unset($_POST['abc']);
}
?>
<form method="post">
    <input type="text" name="abc" />
    <input type="submit" />
</form>


After first submittion echo shows my answer I wrote into text field, but after refreshing/reload page it should be empty or unknow, should not be? So this is that problem ... nothing happen, eho shows same value... you know why?

User avatar
simplypixie
php-forum Active User
php-forum Active User
Posts: 300
Joined: Sun Dec 11, 2011 12:51 am
Location: Shrewsbury, Shropshire
Contact:

Re: erase $_POST data after submition

Postby simplypixie » Sun Nov 17, 2013 9:43 pm

Sorry I can't see the problem and I have just tested your code and when I first submit, the value is echo'd out as expected and when I submit a second time it is not so it is working fine as far as I can see.


Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 2 guests

cron