Link to home
Start Free TrialLog in
Avatar of unitedmp
unitedmpFlag for Australia

asked on

How to use checkbox data in a query

I have a form which i need to select the user from, this uses a query to populate the checkboxes.

This works fine, submits data to the next page and then I need to use the names selected in the checkboxes to do another query.

The problem is the names are submitted as:
name1,name2,name3,name4

How do I seperate these names to use them as individual variables?

I understand I will need to create a query for each name, and that is fine, how do I seperate them in the first place though?
ASKER CERTIFIED SOLUTION
Avatar of _agx_
_agx_
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ie.  You could run one query to get all of the selected names, instead of separate queries.
Avatar of unitedmp

ASKER

Here is what I have so far.

FORM PAGE:

<CFOUTPUT Query="selectgroup">
  <INPUT Type="Checkbox" Name="prjgroup"
    Value="#username#">#fullname#<br />
</CFOUTPUT>

PROCESSING PAGE:

<cfquery datasource="#Application.DSN#" dbtype="odbc" name="findusers">
SELECT *
FROM users
WHERE username IN(#form.prjgroup#)
</cfquery>

This does seem to seperate the values, however i get a different error:
Invalid column name 'second checkbox option'
also, not sure what you mean by  cfsqltype="your type">
now have
<cfquery datasource="#Application.DSN#" dbtype="odbc" name="findusers">
SELECT *
FROM users
WHERE username IN(<cfqueryparam list="yes" value="#form.prjgroup#" cfsqltype="cf_sql_varchar">
</cfquery>

ERROR:
[Macromedia][SQLServer JDBC Driver][SQLServer]Incorrect syntax near '@P2'.
> not sure what you mean by  cfsqltype="your type">

Just replace it with the correct type for your column:  cf_sql_varchar, cf_sql_integer, etc..

> [Macromedia][SQLServer JDBC Driver][SQLServer]Incorrect syntax near '@P2'.
      
You left out the closing parenthesis ).   Try

    WHERE username IN
     (
        <cfqueryparam list="yes" value="#form.prjgroup#" cfsqltype="cf_sql_varchar">
       )

Don't forget - validate the list size.  If the list is empty the query will throw an error.
my mistake, forgot to close the IN with  )

Cheers for your help, works a treat.

Greatr work, thanks for your help
Glad to help