stop inserting data in the database when refreshing the page

后端 未结 10 1277
太阳男子
太阳男子 2020-12-06 02:27

I am looking for a way to stop inserting or sending data in the database when refreshing the page.

here is my code:

user_details_page.php

<         


        
10条回答
  •  执笔经年
    2020-12-06 02:53

    Header the user to a new page :

    if (isset($_POST['submit'])) 
    {
      $user= $_POST['username'];
      $email = $_POST['useremail'];
      $pass= $_POST['password']; 
    
      mysql_query("INSERT INTO table (username, useremail, email) VALUES(`$username','$useremail','$email')");
    
    }
    //best outside the if statement so user isn't stuck on a white blank page.
    header("location: landing_page.php");
    exit;
    

    By doing this the user who refreshes will be refreshing landing_page.php which means it won't do the insert twice.

    best advice: do a check to see if user exists first if so don't insert!

提交回复
热议问题