Sean Kimball
Sean Kimball

Reputation: 4494

Coldfusion8 Parameter index out of range error

I'm doing something stupid, but I don't know what it is, can someone point out to me why I am getting this error:

Parameter index out of range (1 > number of parameters, which is 0). 

From this code,

This form:

<form id="form1" name="form1" method="post" action="?template=/Assets/Plugins/AmericanSurcharges/index.cfm&action=add" class="inputform">
    <tr>
        <td>
            <select name="datamonth">
                <option value=""></option>
                <cfloop from="1" to="12" step="1" index="i">
                    <cfset option = monthasstring(i) /> 
                    <option value="#i#" >#option#</option>
                </cfloop>
            </select>

        </td>
        <td><input name="201data" type="text" id="201" size="6" maxlength="7" value="" class="data" /></td>
        <td><input name="301data" type="text" id="301" size="6" maxlength="7" value="" class="data" /></td>
        <td><input name="304data" type="text" id="304" size="6" maxlength="7" value="" class="data" /></td>
        <td><input name="316data" type="text" id="316" size="6" maxlength="7" value="" class="data" /></td>
        <td><input name="409data" type="text" id="409" size="6" maxlength="7" value="" class="data" /></td>
        <td><input name="430data" type="text" id="430" size="6" maxlength="7" value="" class="data" /></td>
        <td><input name="410data" type="text" id="410" size="6" maxlength="7" value="" class="data" /></td>
        <td><input name="2205data" type="text" id="2205" size="6" maxlength="7" value="" class="data" /></td>
        <td>&nbsp;</td>
        <td><input type="submit" name="submit" id="submit" value=" Insert " /></td>
    </tr>
</form>

posts to this script:

modObj = createObject("component", "surcharge");
command = modObj.insertsurcharges(form);
writeoutput(command);

calling this function:

<cffunction name="insertsurcharges" access="public" output="no" returntype="string" >
    <cfargument name="form" required="yes" type="struct" />

    <cfquery name="insertsurcharges" datasource="#variables.dsn#" result="insertsurcharges_result">
        insert into nas_staticvalues (`datamonth`,`201`,`301`,`304`,`316`,`409`,`430`,`410`,`2205`) values 
            ( 
            `<cfqueryparam value="#form.datamonth#" CFSQLType="CF_SQL_VARCHAR" null="no" maxlength="20" />`,
            `<cfqueryparam value="#form.201data#" CFSQLType="CF_SQL_FLOAT" null="no" scale="4" />`,
            `<cfqueryparam value="#form.301data#" CFSQLType="CF_SQL_FLOAT" null="no" scale="4" />`,
            `<cfqueryparam value="#form.304data#" CFSQLType="CF_SQL_FLOAT" null="no" scale="4" />`,
            `<cfqueryparam value="#form.316data#" CFSQLType="CF_SQL_FLOAT" null="no" scale="4" />`,
            `<cfqueryparam value="#form.409data#" CFSQLType="CF_SQL_FLOAT" null="no" scale="4" />`,
            `<cfqueryparam value="#form.430data#" CFSQLType="CF_SQL_FLOAT" null="no" scale="4" />`,
            `<cfqueryparam value="#form.410data#" CFSQLType="CF_SQL_FLOAT" null="no" scale="4" />`,
            `<cfqueryparam value="#form.2205data#" CFSQLType="CF_SQL_FLOAT" null="no" scale="4" />` 
            )
    </cfquery>

    <cfreturn insertsurcharges_result.GENERATED_KEY />

</cffunction>

and I constantly get the same error.

If I replace all the queryparams with:

'#form.datamonth#',
'#form.201data#',
'#form.301data#',
'#form.304data#',
'#form.316data#',
'#form.409data#',
'#form.430data#',
'#form.410data#',
'#form.2205data#' 

The insert works, also if I take the sql that coldfusion tried to run with the queryparams & just run it on mysql - that works as well!

insert into nas_staticvalues (`datamonth`,`201`,`301`,`304`,`316`,`409`,`430`,`410`,`2205`) values ( ` (param 1) `, ` (param 2) `, ` (param 3) `, ` (param 4) `, ` (param 5) `, ` (param 6) `, ` (param 7) `, ` (param 8) `, ` (param 9) ` ) 

the database accepts 6 digit with 4 decimal places for all the sql_float types.

I must be missing something with the cfqueryparam attributes - right?

Upvotes: 1

Views: 1047

Answers (1)

Jason Dean
Jason Dean

Reputation: 9615

cfqueryparam never needs the quotes. It will construct the query with quotes when it needs them and without when it doesn't. That is one of the awesome parts about using cfqueryparam.

Upvotes: 10

Related Questions