PHP Inserting Duplicates In DB

后端 未结 1 1642
南笙
南笙 2020-12-07 06:14

I\'am attempting to build a register page and the current code runs correctly but I\'am getting duplicate inserts on the DB side. I\'ve researched and have tried several dif

相关标签:
1条回答
  • 2020-12-07 06:46

    If the page is refreshed, or someone hits it again using the "back" button, the data will get resent to the server and thus get inserted twice. You need to redirect the user to another page, or the same page, using the POST/REDIRECT/GET pattern to avoid this. Sending a 303 HTTP response will tell the browser to replace that page in its history and avoid re-sending the posted data.

    if (mysqli_query($connection, $register)) {
        header('Location: index.php', true, 303);
        exit;
    }
    
    0 讨论(0)
提交回复
热议问题