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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

LAST_INSERT_ID() and Cold Fusion

Status
Not open for further replies.

GnegDevelop

Programmer
Joined
Jul 2, 2003
Messages
4
Location
US
I'm trying to use the LAST_INSERT_ID() function to return the last generated ID for a tuple but it won't work within a <cfquery> tag. Can the Last_Insert_id method be used in conjunction with Cold Fusion? I've put my code bellow. Thanks.

<!---Query the DB and insert member information--->

<cfquery datasource=&quot;#request.main_dsn#&quot; name=&quot;insertMem&quot;>
<!--- Insert member --->
INSERT INTO member(
firstName,
lastName,
email,
member_type_fk
)
VALUES( '#form.firstname#',
'#form.lastname#',
'#form.email#',
1
);

<!--- Get the last auto generated num --->
SELECT LAST_INSERT_ID();
</cfquery>

<cfset member_id=insertMem.LAST_INSERT_ID()>

<cfquery datasource=&quot;#request.main_dsn#&quot; name=&quot;insertUser&quot;>
<!--- Insert new username --->
INSERT INTO User(
user_login,
user_password,
member_fk )

VALUES( '#form.Login#',
'#form.Password#',
#member_id# );
</cfquery>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top