?
Solved

If page is refreshed data is written twice to database

Posted on 2008-02-05
3
Medium Priority
?
442 Views
Last Modified: 2013-12-12
I have an HTML form that gets user info and when they press the submit button it will add the data to the database and then display the information they just added.  When the user is on the confirm page, if he pushes refresh it will resubmit the data to the database.  I cannot check to see if the row already exists, because it is okay for there to be multiple rows that are the same (just with a different time stamp).  What is the best way to prevent this from happening?  Thanks!
0
Comment
Question by:CDirenzi
  • 2
3 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 20826988
check out this script to be added to your page:
<script language="JavaScript">
function validate(){
if(document.inputform.field1.value != ""){
if(document.inputform.field2.value != ""){
document.inputform.submit.disabled = false;
}
}
}
function disable(){
document.inputform.submit.disabled = true;
document.inputform.submit.value = "Please wait... Form is being
submitted.";
}
</script>

Open in new window

0
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 400 total points
ID: 20826990
and your form be like this:
<form name="inputform">
<input type="text" name="field1" value="" onblur="javascript:validate();" />
<input type="text" name="field2" value="" onblur="javascript:validate();" />
<input type="submit" name="submit" value="Submit" disabled
onclick="javascript:disable();" />
</form>

Open in new window

0
 
LVL 11

Accepted Solution

by:
vs1784 earned 1600 total points
ID: 20827018
After adding data redirect the page to same page, it will reload the same page. And refreshing will not add data again.

Hope this helps.

Thanks
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

600 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question