I have a form in page1.php
which directs to page2.php
from where the data from the form in page1.php
is inserted into database. after
You should not display your message on page2.php
.
Instead :
page2.php
should deal with the datapage2.php
should redirect to confirmation.php
confirmation.php
which would display the message.
For more informations, take a look at the Post/Redirect/Get pattern.
Edit after the comment : but note that, in any case, you will never be able to prevent the user from re-submitting a form, if he really wants to...
The only solution you'll have is, when a form is submitted, to check in your database if the currently submitted data already exists -- and if it does, refuse to insert it again.
Of course, if the suer changes even a single letter in his input, it won't be the same data anymore...