Click here to Skip to main content
15,893,814 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I've a php web page with a form. After filling the form in web page, I can submit it to the server. But after that, if I refresh the page, it inserts the same record to the database. Is there any solutions to this problem?
Posted

1 solution

Do a trick with several step:
1. create a session variable name datasubmit or any other suitable name and set the value true
i.e $_SESSION['datasubmit']=true; do this process in the first file or first step.
2. Before saving change the value of datasubmit.
3. In the second step before save the data to data change the value to $_SESSION['datasubmit'] to false.


here is an example:
file form.php
PHP
<?php
session_start();
$_SESSION['datasubmit']=false;

?>
<FORM method='post' action='save.php'>
<input name="savedata">
<input name="submit" value="submit">
</FORM>
</input></input>


second file, save.php:
HTML
session_start()
if(isset($_SESSION['datasubmit'])==true && $_SESSION['datasubmit']==true)
{
  //required action to save;
}
else{
 //message or action other than saving.
}
?>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900