How to Protect from double posting insert MySQL
Cara untuk supaya proteksi dari double posting suatu form ke dalam database menggunakan tehnik SESSION.
1. Set a session in the form page
1 2 3 4 5 6 7 8 |
session_start(); $_SESSION[post_only_once] = 1; echo ' < form method="post"> Name < input type="text" name="name"> < input type="submit" value="submit" name="submit"> < /form> '; |
2. Check the session before doing INSERT into MySQL.
1 2 3 4 |
if($_SESSION[post_only_once] == 1) { // here doing insert to mysql } unset($_SESSION[post_only_once]); // remove the session after insert |