Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

insert into database keeps inserting when refreshing...

Status
Not open for further replies.

Ross1811

MIS
Oct 1, 2004
122
0
0
US
Hello Everyone,

I am new at coldfusion, my problem that I am having is making a simple blog page. How are you suppose to insert into your database and still keep going back to the page when done inserting. If someone would "refresh" the page inserts again having no data entered. Is it proper to send it to another page or something? I looked on this page handles it and it sends me to another page it seems "@page=1" My page does not insert the first time a user would visit it, just causes problems after pushing the button submit for a new blog. Please help....

Thanks,
Ross
 
There are two ways to tackle this

Redirection upon submission

Code:
<cfif isDefined("form.formActionButton")>
  ...insert query...
  <cflocation url="blah.cfm?notice=#URLEncodedFormat("Stuff inserted.")#">
</cfif>

...Your form here...

You could put this code in blah.cfm

Code:
<cfif isDefined("url.notice")>
  <script>
    <!--
      <cfoutput>alert('#url.notice#');</cfoutput>
    -->
  </script>
</cfif>

The other method involves storing a timestamp in a session/cookie var and dropping it in a form field in your form.

If you update it with each form submission, you could use a cfif to detect refreshes. The only problem this would cause is two concurrent sessions in different browser windows. Might cause some flaws.

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
I'm not sure if this would work for you, but I know I've written some pages that my company uses to insert credit memo data into sql tables. In my case I have a key field, which is the credit memo number and before I do any inserts I to a query to check and make sure the number isn't already in the system. If it isn't then I skip the insert.
Like so.
<cfquery name="qryCheckExsisting" datasource="myDatasource">
Select CrdMemoNum
From table1
Where CrdMemoNum='#NewCrdMemoNum#'
</cfquery>

Check record count of last query. If it's zero the insert doesn't exists. So it's okay to inser the data.
<cfif qryCheckExsisting.RecordCount EQ 0>
Insert query......
</cfif>

Kenneth
 
That requires another query and you should try to use as few queries as possible. Especially considering how much of a problem CF is in mx and its rumored to be worse in blackstone.

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
Thanks everyone for all your help, this is a great place for technical information and always the first place I check with. These places are hard to find with such great people replying,

Thanks again,
Ross
 
That's what I get for a late night post.. Changed cf to what it was supposed to be: CFQUERY

That requires another query and you should try to use as few queries as possible. Especially considering how much of a problem [red]CFQUERY[/red] is in mx and its rumored to be worse in blackstone.

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top