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 (4 votes, average: 4.75 out of 5)
Loading ... Loading ...
Popularity: 4,779 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

One Comment on “How to Protect from double posting insert MySQL”

  • 28 January, 2010, 19:18

    I dont mean to hijack your forums but I have been looking for work all over the net.There seems to be allot of people here needingsome help and I wanted to drop in and see if I could be of service to anyone.
    Checkout my resume and let me know if I can help out. http://www.linkedin.com/pub/jason-evans/19/a19/462
    Thanks for your Time, Jason

    Like or Dislike: Thumb up 0 Thumb down 0

Leave a Comment

Halaman ini di eksekusi dalam waktu 0.785 detik! (koneksi mayan kenceng nih...)