Preventing multiple data insertion on page reload

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Raju V.K

    #1

    Preventing multiple data insertion on page reload

    I am developing a PHP-mysql database. It is noted that when the
    browser window is refreshed the data is inserted again in the
    database. unfortunately there is no unique keys that I can use to
    verify the existance of the data, so as to prevent the multiple
    insertion. Is there any other way to prevent it otherthan introducing
    another field for this purpose and verifying its existance?


    Regards,

    Raju
  • Daniel Tryba

    #2
    Re: Preventing multiple data insertion on page reload

    Raju V.K <rajuvk@satyam. net.in> wrote:[color=blue]
    > I am developing a PHP-mysql database. It is noted that when the
    > browser window is refreshed the data is inserted again in the
    > database. unfortunately there is no unique keys that I can use to
    > verify the existance of the data, so as to prevent the multiple
    > insertion. Is there any other way to prevent it otherthan introducing
    > another field for this purpose and verifying its existance?[/color]

    While that may be the best way, I often simply redirect
    (header/location) after manipulating data. A browser can still go back a
    couple of pageviews and refresh to reinsert the data but it is
    sufficient for most purposed I think.

    Comment

    • Raj Shekhar

      #3
      Re: Preventing multiple data insertion on page reload

      rajuvk@satyam.n et.in (Raju V.K) writes:
      [color=blue]
      > I am developing a PHP-mysql database. It is noted that when the
      > browser window is refreshed the data is inserted again in the
      > database. unfortunately there is no unique keys that I can use to
      > verify the existance of the data, so as to prevent the multiple
      > insertion. Is there any other way to prevent it otherthan introducing
      > another field for this purpose and verifying its existance?[/color]

      You can use session variables to flag that the insert operation has
      occurred once. i.e.

      if (!isset($_SESSI ON["PAGE_NAME_INSE RT"]))
      {
      /* Do the insertion operation */
      $_SESSION["PAGE_NAME_INSE RT"]=true;
      }

      else
      {

      /* The value have already been inserted. */

      }

      Note that at the page which sends the data to the page which actually
      does the insertion, you might want to unset the
      $_SESSION["PAGE_NAME_INSE RT"] variable. This is needed if the user
      presses "Back" and then changes some values in the form and resubmits.

      --
      Raj Shekhar
      System Administrator, programmer and slacker
      home : http://rajshekhar.net
      blog : http://rajshekhar.net/blog/

      Comment

      • rajuvk@satyam.net.in

        #4
        Re: Preventing multiple data insertion on page reload

        Raj Shekhar wrote:[color=blue]
        > rajuvk@satyam.n et.in (Raju V.K) writes:
        >[color=green]
        > > I am developing a PHP-mysql database. It is noted that when the
        > > browser window is refreshed the data is inserted again in the
        > > database. unfortunately there is no unique keys that I can use to
        > > verify the existance of the data, so as to prevent the multiple
        > > insertion. Is there any other way to prevent it otherthan[/color][/color]
        introducing[color=blue][color=green]
        > > another field for this purpose and verifying its existance?[/color]
        >
        > You can use session variables to flag that the insert operation has
        > occurred once. i.e.
        >
        > if (!isset($_SESSI ON["PAGE_NAME_INSE RT"]))
        > {
        > /* Do the insertion operation */
        > $_SESSION["PAGE_NAME_INSE RT"]=true;
        > }
        >
        > else
        > {
        >
        > /* The value have already been inserted. */
        >
        > }
        >
        > Note that at the page which sends the data to the page which actually
        > does the insertion, you might want to unset the
        > $_SESSION["PAGE_NAME_INSE RT"] variable. This is needed if the user
        > presses "Back" and then changes some values in the form and[/color]
        resubmits.[color=blue]
        >
        > --
        > Raj Shekhar
        > System Administrator, programmer and slacker
        > home : http://rajshekhar.net
        > blog : http://rajshekhar.net/blog/[/color]


        This is a good suggestion, as it does not make a database request. I
        will give it a try.

        Regards,
        Raju

        Comment

        Working...