| | |
Insert query.
Please support our ColdFusion advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Mar 2008
Posts: 5
Reputation:
Solved Threads: 0
Hi everybody!
Could you teach me how to get back the “primary key”: (“id”), from an “insert query”?
*
*
How could I get back the primary key:”id” and send it to another page? (MySQL)
Thanks a lot!
Could you teach me how to get back the “primary key”: (“id”), from an “insert query”?
*
coldfusion Syntax (Toggle Plain Text)
<cffunction name="insertData" access="public"> <cfargument name="formData" type="struct" required="yes"> <cfquery name="qInsert" datasource="mydata"> INSERT INTO mytable (email, firstname, name) VALUES ('#formData.email#', '#formData.firstname#', '#formData.name#') </cfquery> </cffunction>
How could I get back the primary key:”id” and send it to another page? (MySQL)
Thanks a lot!
Last edited by peter_budo; Jun 16th, 2008 at 10:06 am. Reason: Keep It Organized - please use [code] tags
Use SCOPE_IDENTITY(). It will return the id of the record just created, provided the field is set as the identity column.
ColdFusion Syntax (Toggle Plain Text)
<cffunction name="insertData" access="public"> <cfargument name="formData" type="struct" required="yes"> <cfquery name="qInsert" datasource="mydata"> INSERT INTO mytable (email, firstname, name) VALUES ('#formData.email#', '#formData.firstname#', '#formData.name#') SELECT id = SCOPE_IDENTITY() </cfquery> <cfreturn qInsert.id /> </cffunction>
•
•
Join Date: Mar 2008
Posts: 5
Reputation:
Solved Threads: 0
Thank you, cmhampton !
How about cfquery: "result" ?What you prefer?
H.
How about cfquery: "result" ?What you prefer?
H.
•
•
•
•
Use SCOPE_IDENTITY(). It will return the id of the record just created, provided the field is set as the identity column.
ColdFusion Syntax (Toggle Plain Text)
<cffunction name="insertData" access="public"> <cfargument name="formData" type="struct" required="yes"> <cfquery name="qInsert" datasource="mydata"> INSERT INTO mytable (email, firstname, name) VALUES ('#formData.email#', '#formData.firstname#', '#formData.name#') SELECT id = SCOPE_IDENTITY() </cfquery> <cfreturn qInsert.id /> </cffunction>
![]() |
Similar Threads
- How to insert data into database? (JSP)
- need help with insert.php (PHP)
- Update and insert query in one (MySQL)
- database connection(select ,insert query) within javascript function (JSP)
- Problems with INSERT INTO and ADO (Visual Basic 4 / 5 / 6)
- Use variable within Insert side of FormView (ASP.NET)
Other Threads in the ColdFusion Forum
- Previous Thread: title tag
- Next Thread: <cfmail> question
| Thread Tools | Search this Thread |





