Coldfusion8 参数索引超出范围错误

发布于 2024-12-04 14:46:16 字数 4275 浏览 2 评论 0原文

我正在做一些愚蠢的事情,但我不知道它是什么,有人可以向我指出为什么我会收到此错误:

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

从这段代码,

此表单:

<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>

发布到此脚本:

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

调用此函数:

<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>

并且我不断得到同样的错误。

如果我将所有查询参数替换为:

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

则插入有效,而且如果我采用 Coldfusion 尝试使用查询参数运行的 sql,则插入有效。只需在 mysql 上运行它 - 也可以!

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) ` ) 

对于所有 sql_float 类型,数据库接受 6 位小数点后 4 位。

我一定是缺少 cfqueryparam 属性的某些内容 - 对吧?

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> </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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

君勿笑 2024-12-11 14:46:16

cfqueryparam 永远不需要引号。它会在需要时使用引号构造查询,在不需要时则不使用引号构造查询。这是使用 cfqueryparam 的最棒的部分之一。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文