Problem with this query string conversion script

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

  1. #1

    Default Problem with this query string conversion script

    I read the article titled A Cure for Arachnophobia by Ben Forta in the CFDJ
    ([url]http://coldfusion.sys-con.com/read/41702_p.htm[/url]). In it was this script to
    convert url parameters which were sent sperated only by forward slashes into
    something than can be used as a URL parameter. However, when I copied the
    script and tried to get it to work I have been getting this same error. I am
    not stupid enought to even think about questioning the ColdFusion Guru himself
    but what am I doing wrong? Did anyone else read this article and get this to
    work?

    This is the calling page:

    <html>
    <head>
    <title>test</title>
    </head>
    <body>
    <a href="parseURL.cfm?age=30">My age is 30</a>
    </body>
    </html>

    Here is the parseURL.cfm page:

    <!--- Extract "query_string" from full path --->
    <CFSET query_string_length=Len(CGI.PATH_INFO)-Len(CGI.SCRIPT_NAME)>
    <CFSET query_string=Right(CGI.PATH_INFO, query_string_length)>

    <!--- How many items in "query_string? --->
    <CFSET items=ListLen(query_string, "/")>

    <!--- Loop through list, pair of items at a time --->
    <CFLOOP FROM="1" TO="#items#" STEP="2" INDEX="i">
    <!--- Save this URL parameter --->
    <CFPARAM NAME="URL.#ListGetAt(query_string, i, "/")#"
    DEFAULT="#ListGetAt(query_string, i+1, "/")#">

    </CFLOOP>

    <html>
    <head>
    <title>test</title>
    </head>
    <body>
    The query string value is: <cfoutput>#url.age#</cfoutput>
    </body>
    </html>

    Here is the message that I have been getting:

    Parameter 2 of function Right which is now -25 must be a positive integer

    Thanks for the help!

    Jason

    jpesolutions Guest

  2. Similar Questions and Discussions

    1. #39126 [NEW]: String->float->String conversion behavior
      From: bobson at rpg dot pl Operating system: Linux PHP version: 5CVS-2006-10-11 (snap) PHP Bug Type: Unknown/Other Function...
    2. Problem with pound signs in a query string
      I have a form with an address field in which the user may enter a pound sign for an address number. That form is submitted and the page that...
    3. Query string and Parameter Passing Problem
      Hi In the context of a Master/Detail scenario, I am having trouble figuring out the correct syntax for passing a parameter in a query string in a...
    4. Maintain query string and somehow auto refresh a pagewith that string intact
      I have a drill down where on page one the user selects criteria to narrow down the search for a speicific group of employees(like all hired between...
    5. Problem with string and base64binary conversion
      Hi! I have a string I want to save to database via a webmethod. The webmethod takes a dataset where my string is declared as base64binary. I...
  3. #2

    Default Re: Problem with this query string conversion script

    ***SORRY***

    The actual query string that is being sent is:
    <a href="parseURL.cfm/age/30">My age is 30</a>

    And the Error message is:
    Parameter 2 of function Right which is now -18 must be a positive integer

    jpesolutions Guest

  4. #3

    Default Re: Problem with this query string conversion script

    On my system, #CGI.PATH_INFO# equals "/age/30" and not "parseURL.cfm/age/30",
    which results in the negative number error we're getting.

    I wonder what CF version and OS Ben was using for his example? I'm on CF7 and
    Windows XP, IIS.

    A simple fix would be to change this line of code:

    <CFSET items=ListLen(query_string, "/")>

    to this:

    <CFSET items=ListLen(CGI.PATH_INFO, "/")>


    eastinq Guest

  5. #4

    Default Re: Problem with this query string conversion script

    I discovered that the variable are in the wrong order in the first line of the
    code.

    Change:
    <CFSET query_string_length=Len(CGI.PATH_INFO)-Len(CGI.SCRIPT_NAME)>

    To:
    <CFSET query_string_length=Len(CGI.SCRIPT_NAME)-Len(CGI.PATH_INFO)>

    After doing this the script worked great.

    jpesolutions Guest

Posting Permissions

  • You may not post new threads
  • You may not 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