Clearing form data after submission in PHP

I am stuck at the point of clearing form data. After the user submits the form, the data will be added to the database. Perfectly. But if the user refreshes the page, previously entered data is re-entered into the database. I use the post method to send data. I do not use AJAX. The whole page reloads after sending the data. Please help me with this. If there is a way to clear the form data after it is submitted, so that after updating the page no data is added to the database, answer this question.

+5
source share
8 answers

After inserting the data, redirect:

header('Location:'.$_SERVER['PHP_SELF']);

.


, $_GET. :

// Redirect and set $_GET variable
header('Location:'.$_SERVER['PHP_SELF'].'?showmsg=true');

div, :

function show_confirmation()
{
    return isset($_GET['showmsg']) && $_GET['showmsg'] == 'true';
}

:

<div style="display:<?php echo show_confirmation() ? 'block' : 'none'; ?>">
    <!-- Message for user -->
</div>
+8

, post- - . , , . , , .

+1

POST GET , ( , , , ).

, - , ; , , .

, , , ​​ , .

+1

URL- , . URL.

0

. , , .

( ):

session_start();

, , :

$_ SESSION ['form_submitted'] = true;

:

0

html . , .

0

, , - script.

if(saveFormInformation())
{
    header('Location: http://www.example.com/'); //this line instructs browser 
                                                 //to go to example. com 
                                                 //but the webserver will keep executing the rest of the script 
                                                 //unless you instruct it to stop

    die; //this line instructs web server to stop execution of the script
}
0

unset(), .

($ _ POST);

check my answer here: fooobar.com/questions/63257 / ...

0
source

All Articles