Problem is that when I run the code, I seem to be getting unexpected
results. The query runs, and where it should only dump 1 record into the
db it is dumping 2 records that are identical except for the ID field
(which is a MSAccess AutoNum).
My search for a cure is not going well. Can anyone see why this is
happening? The insert that I am using is at the end of the page.
<html>
<head>
<title>VERIFY ADD ITEM</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="" rel="stylesheet" type="text/css">
<cfscript>
/**
* Checks to see if a var is an integer.
* version 1.1 - mod by Raymond Camden
*
* @param varToCheck Value you want to validate as an integer.
* @return Returns a Boolean.
* @author Nathan Dintenfass ([EMAIL PROTECTED])
* @version 1.1, April 10, 2002
*/
function isInt(varToCheck){
return isNumeric(varToCheck) and round(varToCheck) is vartoCheck;
}
function isCurrency(c)
{
if(isNumeric(trim(c)))
{
c = NumberFormat(c,"999999999.00");
//writeOutput(trim(c) & "<br />");
}
else
{
return isNumeric(trim(c));
}
return isCur2(trim(c));
}
function isCur2(n)
{
var dollars = "";
var cents = "";
if (listLen(n, '.') EQ 2)
{
dollars = listFirst(n, '.');
cents = listLast(n, '.');
return (len(cents) EQ 2 AND (isNumeric(dollars) AND
isNumeric(cents)));
}
else
{
return listLen(n, '.') EQ 2;
}
}
</cfscript>
</head>
<body>
<cfif NOT ISDEFINED("FORM.ProductType") OR NOT
ISDEFINED("Form.ProductID") OR NOT ISDEFINED("Form.addAnother") OR NOT
ISDEFINED("Form.Size") OR NOT ISDEFINED("FORM.Price")>
<cfset ErrCnt = 0>
<cfset ErrArr = ArrayNew(1)>
<cfif NOT ISDEFINED("FORM.ProductType")>
<cfset ErrCnt = ErrCnt + 1>
<cfset ErrArr[ErrCnt] = "Form.ProductType: Not Defined. If you get
this message again, contact your system administrator">
</cfif>
<cfif NOT ISDEFINED("FORM.ProductID")>
<cfset ErrCnt = ErrCnt + 1>
<cfset ErrArr[ErrCnt] = "Form.ProductID: Not Defined. If you get
this message again, contact your system administrator">
</cfif>
<cfif NOT ISDEFINED("FORM.addAnother")>
<cfset ErrCnt = ErrCnt + 1>
<cfset ErrArr[ErrCnt] = "Form.AddAnother: Not Defined. If you get
this message again, contact your system administrator">
</cfif>
<cfif NOT ISDEFINED("FORM.Size")>
<cfset ErrCnt = ErrCnt + 1>
<cfset ErrArr[ErrCnt] = "Form.Size: Not Defined. If you get this
message again, contact your system administrator">
</cfif>
<cfif NOT ISDEFINED("FORM.Price")>
<cfset ErrCnt = ErrCnt + 1>
<cfset ErrArr[ErrCnt] = "Form.Price: Not Defined. If you get this
message again, contact your system administrator">
</cfif>
<cfif ErrCnt GT 0>
<div class="PageHeading">Error Messages</div>
<br />
<cfdump var="#ErrArr#">
<cfabort>
</cfif>
</cfif>
<cfset v = StructNew()>
<!--- Product Type --->
<cfset v.PT = "">
<!--- Product ID --->
<cfset v.PID = "">
<!--- AddAnother --->
<cfset v.AA = "">
<!--- Size --->
<cfset v.S="">
<!--- Price --->
<cfset v.P="">
<!--- Best Buy --->
<cfset v.BB = "">
<cfset e = ArrayNew(1)>
<cfset ecnt = 0>
<cfif ISDEFINED("Form.ProductType") AND LEN(TRIM(FORM.ProductType)) GT 0>
<cfif NOT ISNUMERIC(Form.ProductType)>
<cfswitch _expression_="#UCASE(Form.ProductType)#">
<cfcase delimiters="|" value="W|WINE|WINES">
<cfset v.PT = "W">
</cfcase>
<cfcase delimiters="|" value="L|LIQUOR|LIQUORS">
<cfset v.PT = "L">
</cfcase>
<cfdefaultcase>
<cfset ecnt = ecnt+1>
<cfset e[ecnt] = StructNew()>
<cfset e[ecnt].FieldName= "Product Type">
<cfset e[ecnt].ErrorMessage = "Product Type Invalid. Not
Recognized. Valid Entries are: W, WINE, WINES, L, LIQUOR, LIQUORS">
</cfdefaultcase>
</cfswitch>
<cfelse>
<cfset ecnt = ecnt+1>
<cfset e[ecnt] = StructNew()>
<cfset e[ecnt].FieldName= "Product Type">
<cfset e[ecnt].ErrorMessage = "Product Type Invalid. May not
contain numeric data">
</cfif>
<cfelse>
<cfset ecnt = ecnt+1>
<cfset e[ecnt] = StructNew()>
<cfset e[ecnt].FieldName= "Product Type">
<cfset e[ecnt].ErrorMessage = "Product Type Not Found. Try Again.">
</cfif>
<!--- Validate ProductID --->
<cfif ISNUMERIC(FORM.ProductID) AND VAL(Form.ProductID) GT 0>
<cfquery name="verify_product_does_exist" datasource="#DS#">
SELECT * FROM #trim(v.PT)#Product WHERE PID = #Form.ProductID#
</cfquery>
<cfif verify_product_does_exist.recordcount IS 1>
<cfset v.PID = trim(Form.ProductID)>
<cfelse>
<cfset ecnt = ecnt+1>
<cfset e[ecnt] = StructNew()>
<cfset e[ecnt].FieldName= "Product ID">
<cfset e[ecnt].ErrorMessage = "Product ID Invalid. Not Not Found.
Please Try Again">
</cfif>
<cfelse>
<cfset ecnt = ecnt+1>
<cfset e[ecnt] = StructNew()>
<cfset e[ecnt].FieldName= "Product ID">
<cfif NOT ISNUMERIC(FORM.ProductID)>
<cfset e[ecnt].ErrorMessage = "Product ID Invalid. Must be
submitted and Product ID can not contain letters">
<cfelse>
<cfset e[ecnt].ErrorMessage = "Product ID Invalid. Must be
submitted and Product ID cannnot be '0'">
</cfif>
</cfif>
<!--- END PRODUCT ID VALIDATION --->
<!--- PRODUCT SIZE VALIDATION --->
<!--- RULES: MUST BE DEFINED --->
<!--- RULES: MUST BE GT 0 --->
<!--- RULES: MUST BE NUMERIC --->
<!--- RULES: MUST NOT BE THE SAME AS A ITEM ALREADY LISTED --->
<cfif ISDEFINED("Form.Size") AND LEN(TRIM(FORM.Size)) GT 0>
<cfif ISNUMERIC(Form.Size)>
<cfif isInt(Form.Size)>
<cfquery name="verify_size_is_uk_for_prod" datasource="#DS#">
SELECT * FROM
<cfif V.PT EQ 'W'>
WineItems
<cfelseif V.PT EQ 'L'>
LiquorItem
</cfif>
WHERE #V.PT#ProductID = #V.PID# AND Size = #Trim(Form.Size)#
</cfquery>
<cfdump var="#verify_size_is_uk_for_prod#">
<cfif verify_size_is_uk_for_prod.recordcount EQ 0>
<cfset v.s = Trim(Form.Size)>
<cfelseif verify_size_is_uk_for_prod.recordcount EQ 1>
<cfset ecnt = ecnt+1>
<cfset e[ecnt] = StructNew()>
<cfset e[ecnt].FieldName= "Item Size">
<cfset e[ecnt].ErrorMessage = "Item Size Invalid. Item Size Has
Already Been Used. If you wish to modify record, please use <em>Edit
</em> feature. Please Try Again">
<cfelseif verify_size_is_uk_for_prod.recordcount GT 1>
<cfset ecnt = ecnt+1>
<cfset e[ecnt] = StructNew()>
<cfset e[ecnt].FieldName= "Item Size">
<cfset e[ecnt].ErrorMessage = "Item Size ERROR. A <em>
potential internal error</em> has occured. Too many records were
returned while processing your request. Please try again. If this
persists, please contact your system administrator.</strong>">
</cfif>
<cfelse>
<cfset ecnt = ecnt+1>
<cfset e[ecnt] = StructNew()>
<cfset e[ecnt].FieldName= "Item Size">
<cfset e[ecnt].ErrorMessage = "Item Size Invalid. Size Must Be A
Whole Number (Integer). Please Try Again">
</cfif>
<cfelse>
<cfset ecnt = ecnt+1>
<cfset e[ecnt] = StructNew()>
<cfset e[ecnt].FieldName= "Item Size">
<cfset e[ecnt].ErrorMessage = "Item Size Invalid. Size Must Be
Numeric. Please Try Again">
</cfif>
<cfelse>
<cfset ecnt = ecnt+1>
<cfset e[ecnt] = StructNew()>
<cfset e[ecnt].FieldName= "Item Size">
<cfset e[ecnt].ErrorMessage = "Item Size Invalid. Not Not Found.
Please Try Again">
</cfif>
<!--- PRODUCT SIZE VALIDATION --->
<!--- RULES: MUST BE DEFINED --->
<!--- RULES: MUST BE GTE 0.01 --->
<!--- RULES: MUST BE NUMERIC --->
<!--- RULES: MUST NOT BE THE SAME AS A ITEM ALREADY LISTED --->
<cfif ISDEFINED("FORM.Price") AND LEN(TRIM(FORM.Price)) GT 0>
<!---<cfdump var="#Form.price#"> <br> 250 --> <cfdump
var="#isCurrency(Form.price)#">--->
<cfif isCurrency(Form.Price) AND Val(Trim(Form.Price)) GTE 0.01>
<cfset V.P = Trim(Form.Price)>
<cfelse>
<cfset ecnt = ecnt+1>
<cfset e[ecnt] = StructNew()>
<cfset e[ecnt].FieldName= "Item Size">
<cfset e[ecnt].ErrorMessage = "Item Price Invalid. Size Must Be
Numeric AND Be in US Dollar Format (example: 12 or 12.30). Please Try
Again">
</cfif>
<cfelse>
<cfset ecnt = ecnt+1>
<cfset e[ecnt] = StructNew()>
<cfset e[ecnt].FieldName= "Item Price">
<cfset e[ecnt].ErrorMessage = "Item Price Invalid. Not Not Found.
Please Try Again">
</cfif>
<!--- VERIFY BEST BUY --->
<!--- RULES: IF NOT DEFINED: VAL = 0 --->
<!--- If Not 1 or 0, interpret at NO --->
<!--- Alert Override to NO value --->
<cfif ISDEFINED("FORM.BestBuy") AND (VAL(Form.BestBuy) EQ 0 OR
VAL(Form.BestBuy) EQ 1)>
<cfset V.BB = Trim(Form.BestBuy)>
<cfelse>
<cfset V.BB = 0>
</cfif>
<cfset test = 'no'>
<cfif ecnt LTE 0>
<cfquery name="addItem" datasource="#DS#">
INSERT INTO
<cfif V.PT is 'W'>
WineItems
<cfelse>
LiquorItem
</cfif>
(#V.PT#ProductID, Size, Price, BestBuy, Control) VALUES (#V.PID#,
#TRIM(V.S)#,
#TRIM(V.P)#, #Trim(V.BB)#, 'r')
</cfquery>
<br> GOT TO INSERT SECTION <br><cfoutput>
Added: <cfif V.PT is 'W'>Wine<cfelse>Liquor</cfif> ITEM <br><br>
Product ID: #V.PT# - #V.PID# <br>
Item Size #v.s#ml <br>
Item Price $#v.p#<br>
Best Buy? #YesNOFormat(V.BB)# </cfoutput>
<cfelse>
<table width="100%"><tr class="PageHeading"><td>Add Item: Error
Messages</tr></td></table>
<br />
<strong><cfdump var="#ecnt#"></strong>Errors have been found, and we
could not complete your request. Please try to fix them. Thank You. <br />
<cfdump var="#E#">
</cfif>
</body>
</html>
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

