ColdFusion SQL更新与表单

时间:2016-01-19 13:39:49

标签: sql coldfusion

<cfelseif ARGUMENTS.myForm.Submit EQ "Update_what">
    <cfquery name="LOCAL.myURL" datasource="#SERVER.cfc.core.getDSN()#">
        SELECT What_name 
        FROM logboek.tbl_What 
        WHERE What_name = <cfqueryparam cfsqltype="cf_sql_varchar" value="#ARGUMENTS.myForm.What_name#" />
    </cfquery>
    <cfif LOCAL.myURL.RecordCount eq 0>
        <cfreturn VARIABLES.Error.myReturn />   
    <cfelse>
        <cfquery name="LOCAL.myURL" datasource="#SERVER.cfc.core.getDSN()#">
        UPDATE logboek.tbl_What
        SET What_name=<cfqueryparam cfsqltype="cf_sql_varchar" value="#ARGUMENTS.myForm.What_name#" />;
        WHERE What_name=<cfqueryparam value="#ARGUMENTS.myForm.What_name#" cfsqltype="cf_sql_varchar">
        </cfquery>
    </cfif> 

我重写了我的代码,但现在我收到以下错误:

  

queryError string UPDATE logboek.tbl_What SET What_name =&#39; HTML&#39 ;; WHERE What_name =&#39; HTML&#39;。

这是我的表单代码:

<form action="blog.Logboek" method="post" name="Update_what">
    <input type="Text" name="What_name" placeholder="Type what you want to update:">
    <input name="requiredFields"type="hidden" value="What_name" /> 
    <input type="Submit" name="Submit" value="Update_what">
</form>

那么为什么我不能按照我想要的形式更新?有人可以用表单提供更新示例吗?

1 个答案:

答案 0 :(得分:3)

尝试更改

UPDATE logboek.tbl_What SET What_name=<cfqueryparam
cfsqltype="cf_sql_varchar" value="#ARGUMENTS.myForm.What_name#" />;
WHERE What_name=<cfqueryparam value="#ARGUMENTS.myForm.What_name#"
cfsqltype="cf_sql_varchar">

UPDATE logboek.tbl_What SET What_name=<cfqueryparam
cfsqltype="cf_sql_varchar" value="#ARGUMENTS.myForm.What_name#" />
WHERE What_name=<cfqueryparam value="#ARGUMENTS.myForm.What_name#"
cfsqltype="cf_sql_varchar">

我删除了;在设置的What_name行的末尾。