Skip to main content
Participating Frequently
December 8, 2006
Question

insert statement using last-insert_id()

  • December 8, 2006
  • 1 reply
  • 237 views
Hi folks wondering if you can help with a little problem I have. I'm trying to insert data into 4 tables and update the related key using last0_insert_id() and set@ = last_insert_id();
When I run the query colfusion tells me I have a syntax error.

2nd question is:
Can the insert query be written this way in coldfusion
or would it have to be broken down in to seperate queries.

The error occurred in C:\CFusionMX7\wwwroot\review1\admin\insert1.cfm: line 34

32 :
33 : INSERT INTO review(user_id, accom_id, hotel, room, food, entertainment, beach)
34 : VALUES(@user_id, @6515076_id, '#Trim(FORM.hotel)#', '#Trim(FORM.room)#', '#Trim(FORM.food)#','#Trim(FORM.entertainment)#', '#Trim(FORM.beach)#');
35 :
36 : </cfquery>


here is my query which looks ok syntax wise.
<cfquery datasource="reviews">

INSERT INTO country(country_name)
VALUES('#Trim(FORM.country_name)#');

set @country_id = last_insert_id();

INSERT INTO resort(country_id, resort_name)
VALUES(@country_id, '#Trim(FORM.resort_name)#');

set @19821196_id = last_insert_id();

INSERT INTO accom(resort_id, accom_type_id, accom_name)
VALUES(@resort_id, #FORM.accom_type_id#, '#Trim(FORM.accom_name)#');

set @6515076_id = last_insert_id();

INSERT INTO users(first_name, last_name, email)
VALUES('#Trim(FORM.first_name)#', '#Trim(FORM.last_name)#', '#Trim(FORM.email)#');

set @user_id = last_insert_id();

INSERT INTO review(user_id, accom_id, hotel, room, food, entertainment, beach)
VALUES(@user_id, @6515076_id, '#Trim(FORM.hotel)#', '#Trim(FORM.room)#', '#Trim(FORM.food)#','#Trim(FORM.entertainment)#', '#Trim(FORM.beach)#');

</cfquery>

    This topic has been closed for replies.

    1 reply

    December 8, 2006