Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a simple php form, like this:

<?php

if(isset($_POST['myform']))
   // email...
else
   // display form

the problem is that if I refresh the page after I submit the form, it gets submitted twice. How can I prevent this from happening?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
368 views
Welcome To Ask or Share your Answers For Others

1 Answer

You should perform a REDIRECT to a page with a message that the data was inserted... and a back button to go to the form again (if you want to)...

To redirect using PHP use the header function:

header('Location: http://www.example.com/');

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...