But whenever i refresh the page, the the entered values are getting inserted again.How can i prevent this ????

Your form is set up with an HTTP POST handler. Per RFC 2616, POST requests may be non-idempotent (i.e., their processing can affect changes on the server, such as inserting a row into a database). For this reason, browsers (by default) force the user to confirm their intention to re-submit their request with a very conspicuous pop-up.

GET requests, on the other hand, can (in theory) be re-submitted all day long with no change. In practice, however, there is nothing preventing CGI developers from having their GET requests do most of the same things POST requests can, and it's not that uncommon, either. So don't think that switching over to GET will solve your issue.

More to the point, this problem tends to be solved through some combination of Javascript (not always) and a form ID hidden field generated by the server and embedded into the <form> HTML code. The server-side (CGI) code keeps track of these IDs (in RAM, database, whatever), and gracefully rejects any further submissions after the first POST is received. Depending on what the form is for, you can decide whether you'll give the user the option of submitting it anyway, or just throw a big fat error message in their face.

This is not a very Perl-ish response, because while you did have a Perl CGI, the root issue really comes down to a better understanding of CGI. To that end, have a gander at http://www.w3schools.com/, POST (Wikipedia), and useCGI; for a decent head start.


In reply to Re: How to prevent a Reload from resubmitting a form? by rjt
in thread How to prevent a Reload from resubmitting a form? by gayu_justin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.