How to get last value when you make insert query for mysql in coldfusion?
This is what i want to do.
I create an album, and after that it goes automatically to image page. So I need to get last auto increment value in insert coding and redirect to insert image page by sending last auto increment value as parameter.
Example
<CFQUERY NAME=”INSERTALBUM” DATASOURCE=”MYSOURCE”>
INSERT INTO ALBUM (ref_id,albumname,timestamp) VALUES (null,’ALBUM NAME’,NOW())
</CFQUERY>
<CFLOCATION URL=”imagelink.cfm?ref=lastinsertid“>
Please help.
Hi,
I try my best to answer your question
In your insert statement add this after datasource.
<CFQUERY NAME=”INSERTALBUM” DATASOURCE=”MYSOURCE” RESULT=”RESULT”>
And add this
<cfset NewPrimaryKey = result.generatedkey>
<CFOUTPUT>
<CFLOCATION URL=”imagelink.cfm?ref=#NewPrimaryKey#“>
</CFOUTPUT>
Hope this help you solve the problem.