How to Protect from double posting insert MySQL

This item was filled under [ Code Snippet, MySQL, PHP ]

Cara untuk supaya proteksi dari double posting suatu form ke dalam database menggunakan tehnik SESSION.
1. Set a session in the form page

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.

if($_SESSION[post_only_once] == 1) {
  // here doing insert to mysql
}
unset($_SESSION[post_only_once]); // remove the session after insert
Rate this topic:
1 Star2 Stars3 Stars4 Stars5 Stars (6 votes, average: 4.83 out of 5)
Loading ... Loading ...
Popularity: 9,527 views
Tagged with: [ , , ]
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Artikel Sejenis

Leave a Comment

Notify me of followup comments via e-mail. You can also subscribe without commenting.

Halaman ini di eksekusi dalam waktu 3.946 detik! (sedeng lah segini mah...)