Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert value from mulptiple checkboxes 1

Status
Not open for further replies.

Albert3162

Programmer
Jul 13, 2001
18
US
I have table structure as three column
1. Name
2. leading as checkbox
3. assigned as checkbox

When I loop through query I have 100 rows with this data. adn also I've got Name_ID.

How can I insert data into table when user selected several checkboxes
 
This is assuming you're populating your table of 100 names from a query and that you're just setting a yes/ flag on the insert. If so it should work someting like this.

<table cols=3>
<tr>
<td>Name</td>
<td>Leading</td>
<td>Assigned</td>
<tr>
<cfoutput query="qry1">
'Set a counter variable'
<cfset i = #qry1.recordcount#>
'Sets Name field to a hidden variable (Name1,Name2,etc.)'
<input name="Name#i#" value="#Name#" type="Hidden">
<tr>
<td>#Name#</td>
'Sets check box name (Leading1,Leading2,etc.'
<td><input type="CheckBox" name="Leading#i#"></td>
<td><input type="CheckBox" name="Assigned#i#"></td>
<tr>
</table>
'Make sure you pass the number of records in query on submit'
<cfoutput><input name="reccount" value="#qry1.recordcount#" type="Hidden">
</cfoutput>


After submit

<cfloop index="i" from="1" to="#Reccount#">
<cfquery name="qryUpdate" datasource="datasource">
Insert into Table1
(Name_id,Leading,Assigned)

Values
('#Evaluate("Name" & i)#',
<cfif isdefined("Leading" & #i#)>'Y'<else>'N'</cfif>,
<cfif isdefined("Assigned" & #i#)'Y'<else>'N'</cfif>
</cfquery>
</cfloop>

Kenneth
 
<cfset i = #qry1.recordcount#>
will set i to the number of rows in your query (100). It is never changed, so every row will have the same names. (name100, leading100...)

do not use this line
<cfset i = #qry1.recordcount#>
and do not use "i" to create your variables

use this instead.
<input type="CheckBox" name="Leading#qry1.currentRow#">

If you're looping through existing records and you're trying to update them you don't use an insert query, you use update and where name_id = #evaluate("form.name_id"&i)# as your where clause. if you are creating new records the insert will work fine.

also avoid using #'s inside your cftags
if you were to use the line
<cfset i = #qry1.recordcount#>
it should be
<cfset i = qry1.recordcount>

If you don't ask the right questions, you don't get the right answers. A question asked in the right way often points to its own answer. Asking questions is the ABC of diagnosis. Only the inquiring mind solves problems.

-Quote by Edward Hodnett
 
Thanks for correcting me. That's what I get trying to write that at 1:00 am. Sorry folks.

Kenneth
 
we've all been there. :)

If you don't ask the right questions, you don't get the right answers. A question asked in the right way often points to its own answer. Asking questions is the ABC of diagnosis. Only the inquiring mind solves problems.

-Quote by Edward Hodnett
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top