Skip to main content
September 16, 2011
Question

inserting data

  • September 16, 2011
  • 2 replies
  • 469 views

Hello all,

After clicking aruond a simple page i made, I decided 2 try and insert a customer into the customer table that i grab the data from. I figured Im not ready for it. But I decided to go ahead n try to make an insert customer form. When the form is submitted, it directs the user to the action.cfm page. The action.cfm page does the insert query, but if the page is reloaded, then the action page inserts the same record more than once. How do I prevent this from occuring?

please help!

action page code:

<

html>

<head><title>CF Insert Customer Action</title></head>

<body>

<h2>Customer inserted</h2>

<cfif

#Form.Submit# is "Submitted">

<cfquery name="inscustomer" datasource="customers">

Insert into Customers ([First Name],[Last Name],Company,[Job Title],[Business Phone])

values ('#Form.Firstname#','#Form.lastname#','#Form.company#','#Form.jobtitle#','#Form.businessphone#')

</cfquery>

<cfoutput>

<p>Customer #Form.FirstName# #Form.LastName# inserted into database.</p>

<p>#DateFormat(now())#   #TimeFormat(Now())#</p>

</cfoutput>

<cfset #Form.Submit#="SubmittedDone">

</cfif>

</body>

</

html>

~

    This topic has been closed for replies.

    2 replies

    Participating Frequently
    September 16, 2011

    At the end of action.cfm, use CFLOCATION or JavaScript location.href to

    push the user to another page, like a Thank You page. That way a refresh

    can only refresh the thank you page, it can't resubmit the form.

    Inspiring
    September 16, 2011

    insert into customers

    (field1, field2, etc)

    select distinct value1, value2, etc

    where not exists

    (select * from customers

    where field1 = value1

    and field2 = value2

    etc)