WeCodeThings Library
Library of code bits
Glossary    Contact Us
Need a web designer? visit WeCodeThings.Com for more details
Search  
   
Browse by Category


WeCodeThings Library .: ColdFusion .: ColdFusion Insert Data Statement Into a Table using ColdFusion CFC CFQueryParam



ColdFusion Insert Data Statement Into a Table using ColdFusion CFC CFQueryParam

Be sure that when you type out the field names that you use the same sequence when you type out the values. It doesn't matter what sequence you use, just as long as its consistant with what you put in your INSERT INTO statement.

The cfqueryparam ensures that when someone inserts data into one of your tables, the data is the data you are expecting and not a simple SQL drop table statement. This is esential for the security of your insert statement and database.

The cftransaction tag makes sure that everything inside of the tag gets executed first before the statement can be ran again. So if you have 2 people trying to insert a record at the same time, then cftransaction will execute both queries "result" and "qryCurrentTicket" before it runs the code for the second person.

<cftransaction>

    <cfquery result="result" datasource="#mydsn#">

        INSERT INTO tblTicket (tktDate, tktTake, tktPayout, tktPersonID, tktTypeID)

        VALUES (<cfqueryparam value="#FORM.txtDate#" cfsqltype="cf_sql_date">,

                <cfqueryparam value="#FORM.txtTake#" cfsqltype="cf_sql_money">,

                <cfqueryparam value="#FORM.txtPayout#" cfsqltype="cf_sql_money">,

                <cfqueryparam value="#LogIn.psnID#" cfsqltype="cf_sql_integer">,

                <cfqueryparam value="#FORM.txtType#" cfsqltype="cf_sql_integer">);

    </cfquery>

    <cfquery name="qryCurrentTicket" datasource="#mydsn#">

        SELECT MAX(tktID) as tktID

        FROM tblTicket

    </cfquery>

</cftransaction>

 



How helpful was this article to you?

Related Articles

article PHP loop through sql statement and put data into a table using a while loop
Still being new to php, I was trying to...

(No rating)  6-5-2009    Views: 1287   
article Flex 3 Get Data from a CFC ColdFusion using bindable result handler function
More about creating a remote object and...

(No rating)  4-21-2009    Views: 800   
article PHP Simple Insert Into MySQL Database using isset function $_POST
To insert an item into the database, you...

(No rating)  5-8-2009    Views: 1026   

User Comments

Add Comment
No comments have been posted.




.: Powered by Lore .:Code by WeCodeThings Website Design and Development