can anyone help me on how to submit multiple rows in one submission?
this survey form will display a set of skill that derived from table skill. the teacher will hav
Another simple approach for inserting multiple records is an INSERT .. SELECT
. (It is also mentioned in the link banyr posted). Because the skill id's are stored in another table, you can use an IN
clause to SELECT
them. Then insert those values directly into your other table studenSkill
with a simple query, no looping.
INSERT INTO studenSkill ( studenId, skillId )
SELECT <cfqueryparam value="#form.studentId#" cfsqltype="cf_sql_integer">
, skillId
FROM skill
WHERE skillId IN
(
<cfqueryparam value="#form.skillId#" cfsqltype="cf_sql_integer" list="true">
)
<input type="checkbox" name="skillid" value="skillid" checked="checked">
BTW, in case that is not a typo, do not forget the # signs around the query column name ie "skillid"
<input type="checkbox" name="skillid" value="#skillid#" checked="checked">
You should be able to use the following syntax, assuming you're on SQL server 2008:
INSERT INTO StudentSkill (StudentID, SkillID)
VALUES (100, 1), (100, 2), (100, 3)
This method gleaned from here, which also contains a couple of alternative methods.
You'll just need to iterate over the list of IDs in FORM.skillid (assuming that's how your form works) to build up the SQL above. Also, make sure you use <CFQueryParam>
on the values when you build up the SQL. Something like the code below ought to do:
<cfif ListLen(FORM.skillid)>
<cfquery>
INSERT INTO StudentSkill (StudentID, SkillID)
VALUES
<cfloop list="#form.skillid#" index="skill">
(<cfqueryparam value="#form.studentID#" CFSQLType="CF_SQL_INTEGER">,
<cfqueryparam value="#skill#" CFSQLType="CF_SQL_INTEGER">)
</cfloop>
</cfquery>
</cfif>