stop inserting data in the database when refreshing the page

后端 未结 10 1300
太阳男子
太阳男子 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 03:18

    The best way to prevent that is to add header('Location: filename') after your query. Thus in your case,

    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');
    //must be inside the condition to prevent too many redirects
    header('Location: user_details_page.php');
    }
    

提交回复
热议问题