phpmysqlxhtmldouble-submit-prevention

double submission when refresh php


I'm trying to correct the issue of double submit in my script. When I press submit it only updates mysql once(which is what I want). However, when I hit refresh it updates mysql again. It seems to ignore the if statement once the refresh button is hit. What would I do to stop this

here is my code

if (isset($_POST['submitButton'])) { 
//do something
 }


<form action = "table.php" method="post">
<label for="submitButton"></label>
<input type="submit" name="submitButton" id="submitButton"
value="Submit Form"/>
</form>

Solution

  • When you refresh the page - the POST IS SENT AGAIN

    Some browsers actually warn you about that happening.

    To prevent that I do:

    if (isset($_POST['submitButton'])) { 
    //do something
    
    //..do all post stuff
    header('Location: thisPage.php'); //clears POST
    }
    
    
    <form action = "table.php" method="post">
    <label for="submitButton"></label>
    <input type="submit" name="submitButton" id="submitButton"
    value="Submit Form"/>
    </form>