stop inserting data in the database when refreshing the page

后端 未结 10 1306
太阳男子
太阳男子 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:52

    What is going on here is that when you refresh page, the form is submitted twice.

    To prevent this, you can use sessions:

    session_start();
    
    if( $_SESSION['submit'] == $_POST['submit'] && 
         isset($_SESSION['submit'])){
        // user double submitted 
    }
    else {
        // user submitted once
        $_SESSION['submit'] = $_POST['submit'];        
    } 
    

提交回复
热议问题