Inserting FORM data into multiple database tables!

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...

All ColdFusion Tutorials By Author: Pablo Varando
Download the EasyCFM.COM Browser Toolbar!