ColdFusion 一次提交即可插入多个表单域

编程入门 行业动态 更新时间:2024-10-27 19:26:55
本文介绍了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) 个表单字段需要同时插入到数据库中,作为不同的行.所以我循环并增加了字段编号.为了简单起见,我创建了 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
  • ...

我尝试通过这样的循环将字段插入数据库:

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 构造无效

我尝试了各种方法,但找不到正确的语法.任何建议将不胜感激.

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 一次提交即可插入多个表单域

本文发布于:2023-10-26 08:09:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1529589.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   表单   ColdFusion

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!