ColdFusion通过一次提交插入多个表单字段 [英] ColdFusion Insert multiple form fields with one submit

查看:99
本文介绍了ColdFusion通过一次提交插入多个表单字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

摘要:

我有一个CFC成功将一组表单字段插入数据库表。现在我想修改它插入多个记录,但是当我尝试处理动态表单字段名称时会收到错误。

I have a CFC that successfully inserts a single set of form fields into a database table. Now I want to modify it to insert multiple records, but am getting an error when I try to process the dynamic form field names.

详细信息:

我有(5)个表单字段,需要同时插入到db中,作为不同的行。所以我循环和增加字段数。我创建了5个静态行,使其变得简单。

I have (5) form fields that need to be inserted in to the db at the same time, as different rows. So I looped and incremented the field number. I created 5 static rows for it to be simple.

<cfloop index="x" from="1" to="5"> 
 <cfoutput>
    <input name="ITIProgramName#x#" type="text" ..>
    <input name="ITIProgVer#x#" type="text" ..>
  </tr>
 </cfoutput>
 </cfloop>

结果是:


  • ITIPROGRAMNAME1,ITIProgVer1

  • ITIPROGRAMNAME2,ITIProgVer2

  • ITIPROGRAMNAME3,ITIProgVer3


  • ITIPROGRAMNAME1, ITIProgVer1
  • ITIPROGRAMNAME2, ITIProgVer2
  • ITIPROGRAMNAME3, ITIProgVer3
  • ...

我试图通过循环将字段插入数据库,如下所示:

I tried to insert the fields into the database by looping like so:

<cfloop from="1" to="5" index="x" >

    <cfquery datasource="ITSReporting" name="InsertQuery">
    INSERT INTO ITIPRO
        (   ServerID,
            ServerName,
            ProgramName,
            CurrentProgVer,
            LastUser,
            UpDone  )
    VALUES
        (   '#Form.ServerID#',
            '#Form.ServerName#',
            '#Form[ITIProgramName#x#]#',
            '#Form[ITIProgVer#x#]#',
            '#CGI.Auth_User#',
            #CreateODBCDateTime(Now())#
            )
</cfquery>
</cfloop>

但它会产生错误


无效的CFML结构

Invalid CFML construct

我尝试过各种各样的事情,但找不到正确的语法。任何建议将不胜感激。

I've tried all sorts of things, but cannot find the right syntax. Any suggestions would be much appreciated.

推荐答案

变量的格式很接近但不完全一样,只有双引号块。

The format of your variable is close but not quite there, you can only double wrap the # if they are in a quote block.

'#Form["ITIProgramName#x#"]#'

我还建议对sql插入使用一个cfqueryparam你的变量。

I would also suggest using a cfqueryparam around your variables on sql inserts.

这篇关于ColdFusion通过一次提交插入多个表单字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆