如何阻止我的coldfusion Cfquery插入重复的行?

时间:2016-12-15 18:28:10

标签: coldfusion

我有一个非常基本的cfquery插件,它在提交时插入我的表单信息3次。

任何人都知道如何制止这个?

这是我的表格。

http://jsfiddle.net/DTcHh/27952/

表单发送到的页面包含以下cfquery:

    <cfquery datasource="OSAnet-College" result="qDonate">
        INSERT into V2_OnlineDonations(FNAME,LNAME,PHONE,EMAIL,CAUSE,DATEDONATE)
        VALUES (
        <cfqueryparam cfsqltype="cf_sql_varchar" value="#FORM.FNAME#">
        , <cfqueryparam cfsqltype="cf_sql_varchar" value="#FORM.LNAME#">
        , <cfqueryparam cfsqltype="cf_sql_varchar" value="#FORM.PHONE#">
        , <cfqueryparam cfsqltype="cf_sql_varchar" value="#FORM.EMAIL#">
        , <cfqueryparam cfsqltype="cf_sql_varchar" value="#FORM.CAUSE#">
        , <cfqueryparam cfsqltype="cf_sql_timestamp" value="#NOW()#">
        )
    </cfquery>

任何帮助都将不胜感激。

1 个答案:

答案 0 :(得分:1)

尝试这样的事情:

<cfquery datasource="OSAnet-College" result="qDonate">
IF 
(
    NOT EXISTS
    (
        SELECT * FROM V2_OnlineDonations 
        WHERE FNAME = <cfqueryparam cfsqltype="cf_sql_varchar" value="#FORM.FNAME#">
        AND LNAME = <cfqueryparam cfsqltype="cf_sql_varchar" value="#FORM.LNAME#">
        AND PHONE = <cfqueryparam cfsqltype="cf_sql_varchar" value="#FORM.PHONE#">
        AND EMAIL = <cfqueryparam cfsqltype="cf_sql_varchar" value="#FORM.EMAIL#">
        AND CAUSE = <cfqueryparam cfsqltype="cf_sql_varchar" value="#FORM.CAUSE#">
    ) 
)
BEGIN 
    INSERT into V2_OnlineDonations(FNAME,LNAME,PHONE,EMAIL,CAUSE,DATEDONATE)
    VALUES (
    <cfqueryparam cfsqltype="cf_sql_varchar" value="#FORM.FNAME#">
    , <cfqueryparam cfsqltype="cf_sql_varchar" value="#FORM.LNAME#">
    , <cfqueryparam cfsqltype="cf_sql_varchar" value="#FORM.PHONE#">
    , <cfqueryparam cfsqltype="cf_sql_varchar" value="#FORM.EMAIL#">
    , <cfqueryparam cfsqltype="cf_sql_varchar" value="#FORM.CAUSE#">
    , <cfqueryparam cfsqltype="cf_sql_timestamp" value="#NOW()#">
    )
END
</cfquery>