0
How to Prevent Duplicate on page refresh?
i created form using php, mysql. when i refresh the page, it automatically submit previous data. how to resolve it? This is my git link. https://github.com/eforever/RegistrationFormExample
11 Antworten
+ 4
Well, I have an idea, but mind that this is a totally untested. Suppose your form.php submits data to savedata.php; where you process the data (save to database etc.) and once you're done, issue redirection by:
header("location:http://localhost/form.php?status=1");
and in your form.php you check the $_GET for this argument;
if(isset($_GET['status']))
{
if($_GET['status'] == '1')
// server said data had been saved
}
I don't even know if it will work, but maybe you can try : )
+ 5
Without the code, it's pretty hard to debug, if not impossible.
+ 3
Check this article may it help you
http://webdevelopmentscripts.com/26-prevent-submit-on-page-refresh
+ 3
Comment the header to see the echo output, the echo output isn't there anymore because of redirection by header location call.
+ 3
The article didn't say anything about getting message from server, I don't know how it's done, sorry.
+ 2
I don't know that, as I said, it was just a thought, of course the URL in address bar showed that because it was GET method : )
An alternative for this, I guess is to show message in savedata.php to notify user that operation succeeded, and put a link (button) to redirect to form.php again.
But I guess the best way to do this would be to use AJAX, as it works asynchronously and transparent, data is transferred back and forth in background, and no redirect or page reload was needed.
There are plenty tutorials out there for learning, perhaps start looking at w3schools, it's lessons are beginner friendly : )
+ 1
<html>
<!-- disallow browser cache -->
<meta HTTP-EQUIV="Pragma" content="no-cache">
<meta HTTP-EQUIV="Expires" content="-1" >
<?php
if(isset($_POST['sdf'])){
echo 'POSTED';
header('Location:http://localhost/post.php');
}else{
echo 'no values' ;
}
?>
<form action='' method='post'>
<input type='text' name='sdf' value='sdf'>
<input type='submit' value='submit'>
</form>
</html>
you are right. but, from above code echo not working. header(); only working.
+ 1
thank you
+ 1
its working. but when i refresh this page, still it showing same message because of url. how to reset the url?
0
https://github.com/eforever/RegistrationFormExample This is my github link of code. Please check it.
0
then how to get message from server?