•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the ColdFusion section within the Web Development category of DaniWeb, a massive community of 427,382 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,037 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ColdFusion advertiser: Programming Forums
Views: 1447 | Replies: 3 | Solved
![]() |
•
•
Join Date: Mar 2008
Posts: 5
Reputation:
Rep Power: 0
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 9: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:
Rep Power: 0
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>
![]() |
•
•
•
•
•
•
•
•
DaniWeb ColdFusion Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- need help with insert.php (PHP)
- How to insert data into database? (JSP)
- 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


Linear Mode