I would like to find out the CF code to insert data from one form into two tables.
Is this possible?

Yes, this is possible Smile

The easiest way to achieve this is to create "two" separate inserts! Wink

Let's say you have a form that a user enters the following:

FirstName,
LastName,
Email,
Phone
CC Number,
CC Expiration

You would create two queries as follows:
<!--- This query inserts the customer --->
<cfquery name="qAddCustomer" datasource="YourDSN">
INSERT INTO Members(
                    FirstName,
                    LastName,
                    Email,
                    Phone
                    )
              VALUES(
                    '#FORM.FirstName#',
                    '#FORM.LastName#',
                    '#FORM.Email#',
                    '#FORM.Phone#'
                   )
</cfquery>

<!--- The next things would be to insert the credit card information --->
<cfquery name="qAddCCINfo" datasource="YourDSN">
INSERT INTO CC(
                FirstName,
                LastName,

                CC_Number,
                CC_Expiration
               )
        VALUES(
                '#FORM.FirstName#',
                    '#FORM.LastName#',

                '#FORM.CC_Number#',
                '#FORM.CC_Expiration#'
               )
</cfquery>

Notice that I have used the FirstName and LastName in both queries, you can use existing variables as many times as you'd like in a page!

Questions? Comments? Email Me...

About This Tutorial
Author: Pablo Varando
Skill Level: Beginner 
 
 
 
Platforms Tested: CF5
Total Views: 55,409
Submission Date: October 15, 2002
Last Update Date: June 05, 2009
All Tutorials By This Autor: 47
Discuss This Tutorial
  • How to create a database and a form to book hotels from my site without connect to the hotels directly, and make payments from paypal

  • Nice, but how to update two database tables with the formfield values? Gr, kabbi

  • b

  • This is something I suggest you start a thread on the forums about, as it will require back and forth conversation to find solution.

  • How can i develop the codes where only one time result is display for the same date.But the problem is that it is a different categories.For example to track the allowance for the day and night shift.If they work more than 6 hours, it will considered OT and they will claim only 1 allowance.but if they claim another OT for another 6 hours on the same date but under different categories, it will still counted as 1 allowance for that day. Plz reply a.s.a.p. Thankz!

Advertisement

Sponsored By...
Powered By...