Search code examples
phpmysqlrefreshrecords

PHP function running on every refresh


Hi i have a function which adds a record to a database. After I have initially clicked submit if I refresh the page it will repeat the function again and again.

The code I am using to call the function is as follows.

if(isset($_POST["submitTask"])){
    insertTask();
};

I am new to mySQL and PHP as I used to use ASP and SQl but I cannot find a solution for php, Thanks in advance.


Solution

  • After submitting the form:

    if(isset($_POST["submitTask"])){
      insertTask();
      header("Location:your_form_page.php");
    }
    

    This redirection will clear all form submissions as page is redirecting, no form will be submitted.