Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to use checkbox data in a query

Posted on 2007-11-28
9
Medium Priority
?
841 Views
Last Modified: 2013-12-24
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?
0
Comment
Question by:unitedmp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 52

Accepted Solution

by:
_agx_ earned 2000 total points
ID: 20370529
An easier option is to give all of the checkboxes the same name.

<cfoutput query="yourQuery">
   <input type="checkbox" name="name" ...>
</cfoutput>

Then the values will be submitted as a comma separated:

form.name = value1, value2, value3

You can then use the values with an IN (....) clause in your query.  Though you must check that the list is not empty first.

<cfquery ....>
     SELECT   TheColumns
     FROM     YourTable
     WHERE   TheColumn IN (  <cfqueryparam value="#form.name#" list="true" cfsqltype="your type"> )
</cfquery>

0
 
LVL 52

Expert Comment

by:_agx_
ID: 20370535
ie.  You could run one query to get all of the selected names, instead of separate queries.
0
 
LVL 1

Author Comment

by:unitedmp
ID: 20370586
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'
0
Plesk WordPress Toolkit

Plesk's WordPress Toolkit allows server administrators, resellers and customers to manage their WordPress instances, enabling a variety of development workflows for WordPress admins of all skill levels, from beginners to pros.

See why 2/3 of Plesk servers use it.

 
LVL 1

Author Comment

by:unitedmp
ID: 20370593
also, not sure what you mean by  cfsqltype="your type">
0
 
LVL 1

Author Comment

by:unitedmp
ID: 20370602
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'.
0
 
LVL 52

Expert Comment

by:_agx_
ID: 20370639
> 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.
0
 
LVL 1

Author Comment

by:unitedmp
ID: 20370648
my mistake, forgot to close the IN with  )

Cheers for your help, works a treat.

0
 
LVL 1

Author Closing Comment

by:unitedmp
ID: 31411569
Greatr work, thanks for your help
0
 
LVL 52

Expert Comment

by:_agx_
ID: 20370661
Glad to help
0

Featured Post

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

660 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question