我在做一些愚蠢的事情,但我不知道它是什么,有人能指出我为什么得到这个错误:
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> </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>
和我总是得到相同的错误
如果我将所有queryparams替换为:
'#form.datamonth#',
'#form.201data#',
'#form.301data#',
'#form.304data#',
'#form.316data#',
'#form.409data#',
'#form.430data#',
'#form.410data#',
'#form.2205data#'
插入工作,也如果我采取sql coldfusion试图运行与queryparams &只需在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属性的东西-对吧?
cfqueryparam不需要引号。它将在需要时使用引号来构造查询,而在不需要时不使用引号。这是使用cfqueryparam的优点之一。