Using selection list in search query

Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.

  1. #1

    Default Using selection list in search query

    Is there something new in CFMX 6.1 that causes the following statement to not
    work correctly? I get an error when trying to load the page. I'd really like to
    be able to use a selection list for multiple committee names in my search
    query. Thanks. <cfquery name='etc' datasourceu='etc'> SELECT * FROM contacts
    WHERE committees in (#PreserveSingleQuotes(form.selectcom)#) </cfquery> Error
    Occurred While Processing Request The system has attempted to use an
    undefined value, which usually indicates a programming error, either in your
    code or some system code. Null Pointers are another name for undefined values.
    The error occurred in D:\e-caa.com\wwwroot\user\groupem\2selectcom.cfm:
    line 5 3 : 4 : <cfquery name='rsChEmail' datasource=#MM_Concaa_DSN#
    username=#MM_Concaa_USERNAME# password=#MM_Concaa_PASSWORD#> 5 : SELECT * FROM
    contacts WHERE committees in (#PreserveSingleQuotes(form.selectcom)#) 6 :
    </cfquery>

    tharring Guest

  2. Similar Questions and Discussions

    1. drop down list selection
      Hi all There's probably a simple answer to this - but I don't know it! I have a drop-down list, populated from a database. When a user enters...
    2. List box not retaining selection
      I have a drop-down list box, populated from a database table. It works fine, but after making a selection from the drop-down list the boxn goes...
    3. PHP selection list
      Can anyone tell how to get the selection value stored in the variable and use that selection to produce another selection list .... hope you...
    4. List box selection
      I have a list of objects in a list box that I need to select all at once. Is there a way to do this?
    5. Selection of records in list
      Dear folks: I was wondering how to query MySQL to display only a selection (1-20, 21-40) of a query in an HTML list. Can that be done in an SQL...
  3. #2

    Default Re: Using selection list in search query

    form.selectcom is the "undefined value"

    Do you check the existance of form.selectcom before using it?

    I dont think it caused by function PreserveSingleQuotes.
    toniu27 Guest

  4. #3

    Default Re: Using selection list in search query

    Before you use the variable you can just check if it exists to make sure that
    there was something selected by the user on the form.

    You should always check if a variable exists if it is coming from a checkbox
    or radio box on the form as if nothing is selected by the user the parameter
    will not be passed through from the form at all.

    Even if you've used a SELECT box the user could have selected something with
    no value in which case the variable will be empty. Doing a query on WHERE
    Committees in () will produce an error too so you could put a CFIF
    Trim(Variable) NEQ '' around the list comparison within the query too.

    HTH



    <cfquery name="rsChEmail" datasource=#MM_Concaa_DSN#
    username=#MM_Concaa_USERNAME# password=#MM_Concaa_PASSWORD#>
    SELECT *
    FROM contacts
    <CFIF IsDefined("form.selectcom") AND Trim(form.selectcom) NEQ ''>
    WHERE committees in (#PreserveSingleQuotes(form.selectcom)#)
    <CFELSE>
    WHERE 0=1
    </CFIF>
    </cfquery>

    zoeski80 Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139