Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get ID or DataRow of new insert record.

Status
Not open for further replies.

xtendscott

Programmer
Apr 21, 2003
276
US
I have a create new user page and wondering if there is a way to get the JustCreated record ID or something without performing another query.

Or what is a good process for confirming email address by sending an email with a confirm Code? Generate it up front? How do you make sure it is unique?

Thanks.
 
I cant help you with the email, but here is a SQL trick I just picked up...I havent even tried it myself yet so I make no promises.

<cfquery name="myQuery"....>
INSERT INTO blah (field1, field2....)
VALUES (var1, var2....)
SELECT ID
</cfquery>

<cfoutput>
myQuery.ID
</cfoutput>

 
there are several ways to get the id of the just-inserted row

the most efficient method depends on the database, and since you did not say which one it is, i cannot tell you which method to use

see this article: Retrieving last row inserted (registration is required but it's free)

as for your other question, yes, that's a good way, generate it up front

what's a good way to make sure it's unique?

generate a random number and insert it along with the email address when adding the new user, by having a unique constraint on the confirm number column

rudy
SQL Consulting
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top