cookmyster
asked on
Getting the last record insert
Hi,
So i am doing a copy fuction.. and I insert the record and using a ID from the session.id...
So after the insert statement i run a select statemetn with the ID and can return all the records from that ID.. but i want to get the last entry by that ID in the select statement... I am not sure how to do that??
Thx,
Rich
So i am doing a copy fuction.. and I insert the record and using a ID from the session.id...
So after the insert statement i run a select statemetn with the ID and can return all the records from that ID.. but i want to get the last entry by that ID in the select statement... I am not sure how to do that??
Thx,
Rich
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
also, if above is the key to your question, you seriously need to elaborate what you are doing
oops! Statement Corrected
also, if above is not the key to your question, you seriously need to elaborate what you are doing
also, if above is not the key to your question, you seriously need to elaborate what you are doing
ASKER
I am getting this error...
Element GENERATED_KEY is undefined in LASTID.
Element GENERATED_KEY is undefined in LASTID.
can u show me how you are doing it so i can check
ASKER
<cfset today = #dateformat(now(), "mm/dd/yy")#>
<cfquery result="lastID" name="jobinsert" datasource="#Application.d bname#" username="#Application.use rname#" password="#application.pas sword#" dbtype="ODBC">
insert into jobs (company_id, job_title, job_location, job_description, job_qualifications, job_otherinfo, job_salary, job_date, job_contactname, job_email)
values ('#session.cid#', '#form.txtjobtitle#', '#jobinfo.job_location#', '#jobinfo.job_description# ', '#jobinfo.job_qualificatio ns#', '#jobinfo.job_otherinfo#', '#jobinfo.job_salary#', now(), '#jobinfo.job_contactname# ', '#jobinfo.job_email#')
</cfquery>
<cfset lastDI = lastID.GENERATED_KEY>
<cfoutput>#lastDI#</cfoutp ut>
<cfquery result="lastID" name="jobinsert" datasource="#Application.d
insert into jobs (company_id, job_title, job_location, job_description, job_qualifications, job_otherinfo, job_salary, job_date, job_contactname, job_email)
values ('#session.cid#', '#form.txtjobtitle#', '#jobinfo.job_location#', '#jobinfo.job_description#
</cfquery>
<cfset lastDI = lastID.GENERATED_KEY>
<cfoutput>#lastDI#</cfoutp
are u trying like this
<cfquery name="addData" datasource="#DSN#" result="addDataResult">
INSERT INTO tbldata(Path,Pathname)
VALUES
(<cfqueryparam value="#path#" cfsqltype="CF_SQL_VARCHAR">,
<cfqueryparam value="#pathname#" cfsqltype="CF_SQL_VARCHAR">)
</cfquery>
<cfset variables.newID = addDataResult.GENERATED_KEY>
why are u using " dbtype="ODBC", its no needed
Check the Code i gave it
Check the Code i gave it
i forgot to ask, are you using Coldfusion 8 and above, if yes, then the code i gave u will work
ASKER
I am using coldfusion 9.. and i took the ODBC off... still kicking the error....
(no points)
The variable is for MySQL if you're using a different database, please let us know
<cfset today = #dateformat(now(), "mm/dd/yy")#>
<cfquery result="lastID" name="jobinsert" datasource="#Application.d bname#" username="#Application.use rname#" password="#application.pas sword#" dbtype="ODBC">
insert into jobs (company_id, job_title, job_location, job_description, job_qualifications, job_otherinfo, job_salary, job_date, job_contactname, job_email)
values ('#session.cid#', '#form.txtjobtitle#', '#jobinfo.job_location#', '#jobinfo.job_description# ', '#jobinfo.job_qualificatio ns#', '#jobinfo.job_otherinfo#', '#jobinfo.job_salary#', now(), '#jobinfo.job_contactname# ', '#jobinfo.job_email#')
</cfquery>
You can dump the variable...
<cfdump var="#lastID#">
The variable is for MySQL if you're using a different database, please let us know
<cfset today = #dateformat(now(), "mm/dd/yy")#>
<cfquery result="lastID" name="jobinsert" datasource="#Application.d
insert into jobs (company_id, job_title, job_location, job_description, job_qualifications, job_otherinfo, job_salary, job_date, job_contactname, job_email)
values ('#session.cid#', '#form.txtjobtitle#', '#jobinfo.job_location#', '#jobinfo.job_description#
</cfquery>
You can dump the variable...
<cfdump var="#lastID#">
do this thing, runa simple test
<cfquery datasource="test" result="result">
insert into test(name)
values('myselfrandhawa')
</cfquery>
<cfdump var="#result#">
make sure test table exists and change the dsn name
<cfquery datasource="test" result="result">
insert into test(name)
values('myselfrandhawa')
</cfquery>
<cfdump var="#result#">
make sure test table exists and change the dsn name
(no points)
> I am getting this error...
> Element GENERATED_KEY is undefined in LASTID.
Silly question, but your table does have an AUTOINCREMENT column correct?
> I am getting this error...
> Element GENERATED_KEY is undefined in LASTID.
Silly question, but your table does have an AUTOINCREMENT column correct?
ASKER
Hey Guys... figured the problem out... i add it pointing to an access database instead of my mysql database. So they original solutions did work...
thank you for all your help
thank you for all your help
Open in new window
.