Quantcast
Channel: Adobe Community : Popular Discussions - ColdFusion
Viewing all articles
Browse latest Browse all 14291

How do I not insert empty value into mySQL loop

$
0
0

How do I prevent my loop from trying to insert an empty value into mySQL database? The form I am using has four rows automatically created. If they only fill in three rows than I get problems with the fourth row being empty.  Below is my code that works fine as long as they don't leave a field empty.

 

<cfloop from="1" to="#form.numba#" index="idx">

    <cfset getqty = form["qty" & idx]>

    <cfset getitem = form["item" & idx]>

    <cfset getunit = form["unit" & idx]>

    <cfset gettotal = form["total" & idx]>

 

<cfquery name="insertItems" datasource="#application.dsn#">

INSERT into items

                (orderID,

                qty,

                item,

                unit,

                total

            )

VALUES(

<cfqueryparam value="#getoid#" CFSQLType="CF_SQL_INTEGER" >,

<cfqueryparam value="#getqty#" CFSQLType="CF_SQL_INTEGER" >,

<cfqueryparam value="#getitem#" CFSQLType="CF_SQL_VARCHAR" >,

<cfqueryparam value="#getunit#" CFSQLType="CF_SQL_INTEGER" >,

<cfqueryparam value="#gettotal#" CFSQLType="CF_SQL_INTEGER" >

)

</cfquery>

</cfloop>   

 

Thanks in advance.


Viewing all articles
Browse latest Browse all 14291

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>