Pete wrote:
> If a user only selects one checkbox and hits submit then everything works
> fine.  I would have the values 3,2 to work with.  3 being the value for
> pracarealist and 2 being the value for the staffed.
> 
> If a user selects multiple checkboxes, the it falls over.  I get values such
> as 2,4,5,6,2 - with 2,4,5,6 being in the pracarealist column and 2 bing the
> staffed.  In this example I need to write 4 records into the db, i.e, 
> 2,2
> 4,2
> 5,2
> 6,2
> 
> 
> Any suggestions as to how to handle this?  My code is below.
> 
> Also I need to be handle if no selections are made (its not doing this
> correctly at present.   
> 
> <cfparam name="form.pracarealist" default="0"> 
> 
> <cfquery name="qInsertStaffPracAreas" datasource="#request.db_dsn#"
> username="#request.db_login#" password="#request.db_pwd#">
> <cfloop index="pa" list="#form.pracarealist#"> 
> INSERT INTO tbl_staffpracareas(practiceid,staffid)
> VALUES(#form.pracarealist#,#form.staffid#)
> </cfloop>
> </cfquery>
> 
> 

In the query above, you are looping over the list, but then trying to 
insert the list...you need to insert the index value...
INSERT INTO tbl_staffpracareas(practiceid,staffid)
VALUES(#pa#,#form.staffid#)

As for handling when no selections are made, test for your 
form.pracarealist EQ 0 or take out the cfparam and test for the 
existence of the form.pracarealist variable.

Also, I just saw your message saying you are using MySQL...by default it 
will not accept multiple statements in a query batch, so the above 
method may not work at all, but I believe the solution that Michael sent 
will work.


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Introducing the Fusion Authority Quarterly Update. 80 pages of hard-hitting,
up-to-date ColdFusion information by your peers, delivered to your door four 
times a year.
http://www.fusionauthority.com/quarterly

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:261656
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4

Reply via email to