pulse239
asked on
My item number is storing a zero when using an array. How do I fix this?
<cfset productList="#pid#">
<cfset productListArray = listToArray(productList,", ",false,tr ue)>
<cfloop array="#productListArray#" index="i">
<cfquery name="insertFlyerProducts" datasource="datasource">
insert into flyer_vendor_campaign_prod ucts (fid,pid,vendor_partno,sho rt_descrip tion,listp rice,disco unt,stndne t,promonet ,selling_u nit,vcode, pnew)
values (#fid#,#i#,'#vendor_partno #','#short _descripti on#',#list price#,#di scount#,#s tndnet#,#p romonet#,' #selling_u nit#','#vc ode#','#pn ew#')
</cfquery>
<cfset productListArray = listToArray(productList,",
<cfloop array="#productListArray#"
<cfquery name="insertFlyerProducts"
insert into flyer_vendor_campaign_prod
values (#fid#,#i#,'#vendor_partno
</cfquery>
ASKER
The values in the array are the product ID which is supposed to be "i". When I output the array, the values display correctly, but don't store correctly.
Thanks, but that doesn't answer all of the questions. Most likely you just need to use cfqueryparam, but .. that's just a guess without more info.
Without knowing what the #i# value contains, or what type of column its stored in (varchar, etc..) I can't tell you how to fix the problem ;-) So
1) what's an example of the #i# value ?
2) what's the data type of the PID column (varchar, datetime, integer, ...?)
Without knowing what the #i# value contains, or what type of column its stored in (varchar, etc..) I can't tell you how to fix the problem ;-) So
1) what's an example of the #i# value ?
2) what's the data type of the PID column (varchar, datetime, integer, ...?)
ASKER
i is a number or INT value in the database.
There's no obvious reason a "number" would not insert correctly into an INT column - even without cfqueryparam. But like I said, we can't tell you why it's 0 if we don't even know what value you're trying to insert! ;-)
I've asked twice, but you haven't posted it. Is there a reason you can't provide an example of the value you're inserting?
I've asked twice, but you haven't posted it. Is there a reason you can't provide an example of the value you're inserting?
ASKER
I am trying to insert number 123455 as a test. Could this be the issue?
No, that number is fine for an INT column. To confirm, I tested it w/SQL 2005 and it ran w/o issue. So there's something else going on (different values, different data type,e tc...)
(Retyped from another screen, so ignore any typos ...)
<cfquery ....>
CREATE TABLE TestTable ( PID INT )
</cfquery>
<cfset productListArray = listToArray("123455,99999" , ",", false, true)>
<cfloop array="#productListArray#" index="i">
<cfquery ...>
INSERT INTO TestTable ( PID )
VALUES ( #i# )
</cfquery>
</cfloop>
<!--- dump results (showed 2 records as expected) --->
<cfquery name="getResults" ....>
SELECT * FROM TestTable
</cfquery>
<cfdump var="#getResults#">
(Retyped from another screen, so ignore any typos ...)
<cfquery ....>
CREATE TABLE TestTable ( PID INT )
</cfquery>
<cfset productListArray = listToArray("123455,99999"
<cfloop array="#productListArray#"
<cfquery ...>
INSERT INTO TestTable ( PID )
VALUES ( #i# )
</cfquery>
</cfloop>
<!--- dump results (showed 2 records as expected) --->
<cfquery name="getResults" ....>
SELECT * FROM TestTable
</cfquery>
<cfdump var="#getResults#">
try using the val around the #i#, and see which values are going as 0 in the database, might help in generating your issues and checking where exactly the problem lies
like this
#val(i)#
like this
#val(i)#
ASKER
It is defiantly not reading the number. It passes as a NULL value. Any idea why this would be occurring?
<cfset productList="#pid#">
<cfset productListArray = listToArray("productList", ",", false, true)>
<cfloop array="#productListArray#" index="i">
<cfquery name="insertFlyerProducts" datasource="datasource">
insert into flyer_vendor_campaign_prod ucts (fid,pid,vendor_partno,sho rt_descrip tion,listp rice,disco unt,stndne t,promonet ,selling_u nit,vcode, pnew)
values (#fid#,#val(i)#,'#vendor_p artno#','# short_desc ription#', #listprice #,#discoun t#,#stndne t#,#promon et#,'#sell ing_unit#' ,'#vcode#' ,'#pnew#')
</cfquery>
<cfset productList="#pid#">
<cfset productListArray = listToArray("productList",
<cfloop array="#productListArray#"
<cfquery name="insertFlyerProducts"
insert into flyer_vendor_campaign_prod
values (#fid#,#val(i)#,'#vendor_p
</cfquery>
<cfset productListArray = listToArray( "productList", ",", false, true)>Oh wait... that's different than your original code. By putting quotes around the variable name you're inserting the literal string "productList" - NOT the contents of a variable named productList.
Remove the quotes, and dump the array before your insert to make sure it actually contains the numbers you said it does, not the string "productList":
<cfset productListArray = listToArray( productList , ",", false, true)>
<cfdump var="#productListArray#" label="See what you're inserting....">
<cfloop array="#productListArray#"
<cfoutput>
preparing to insert PID = #i#<br>
</cfoutput>
..... query ....
</cfloop>
ASKER
I have inserted this:
<cfset productListArray = listToArray( productList , ",", false, true)>
<cfdump var="#productListArray#" label="i">
<cfoutput>#i#</cfoutput><c fabort>
and when I try to display what I am inserting it shows:
Variable I is undefined.
The error occurred in D:/Inetpub/nisscorest/admi n/vendors/ addNewProd uct.cfm: line 17
15 : <cfset productListArray = listToArray( productList , ",", false, true)>
16 : <cfdump var="#productListArray#" label="i">
17 : <cfoutput>#i#</cfoutput><c fabort>
18 : <cfif pnew is "no">
19 : <cfloop array="#productListArray#" index="i">
<cfset productListArray = listToArray( productList , ",", false, true)>
<cfdump var="#productListArray#" label="i">
<cfoutput>#i#</cfoutput><c
and when I try to display what I am inserting it shows:
Variable I is undefined.
The error occurred in D:/Inetpub/nisscorest/admi
15 : <cfset productListArray = listToArray( productList , ",", false, true)>
16 : <cfdump var="#productListArray#" label="i">
17 : <cfoutput>#i#</cfoutput><c
18 : <cfif pnew is "no">
19 : <cfloop array="#productListArray#"
ASKER
When I remove 'label' and just have this code:
<cfset productList="#pid#">
<cfset productListArray = listToArray( productList , ",", false, true)>
<cfdump var="#productListArray#">
<cfoutput>#productListArra y#</cfoutp ut><cfabor t>
I get this:
Complex object types cannot be converted to simple values.
The expression has requested a variable or an intermediate expression result as a simple value. However, the result cannot be converted to a simple value. Simple values are strings, numbers, boolean values, and date/time values. Queries, arrays, and COM objects are examples of complex values.
The most likely cause of the error is that you tried to use a complex value as a simple one. For example, you tried to use a query variable in a cfif tag.
The error occurred in D:/Inetpub/nisscorest/admi n/vendors/ addNewProd uct.cfm: line 20
18 : <cfset productListArray = listToArray( productList , ",", false, true)>
19 : <cfdump var="#productListArray#">
20 : <cfoutput>#productListArra y#</cfoutp ut><cfabor t>
21 : <cfif pnew is "no">
22 : <cfloop array="#productListArray#" index="i">
<cfset productList="#pid#">
<cfset productListArray = listToArray( productList , ",", false, true)>
<cfdump var="#productListArray#">
<cfoutput>#productListArra
I get this:
Complex object types cannot be converted to simple values.
The expression has requested a variable or an intermediate expression result as a simple value. However, the result cannot be converted to a simple value. Simple values are strings, numbers, boolean values, and date/time values. Queries, arrays, and COM objects are examples of complex values.
The most likely cause of the error is that you tried to use a complex value as a simple one. For example, you tried to use a query variable in a cfif tag.
The error occurred in D:/Inetpub/nisscorest/admi
18 : <cfset productListArray = listToArray( productList , ",", false, true)>
19 : <cfdump var="#productListArray#">
20 : <cfoutput>#productListArra
21 : <cfif pnew is "no">
22 : <cfloop array="#productListArray#"
just remove the <cfoutput>#productListArra y#</cfoutp ut> and only dump and abort, what you se and can you post the image of that
ASKER
If I remove the array, and just try to use the productList, I get this error, but it looks like I'm almost there. I double checked the variable types with the code and the numeric and int fields have no quotes and the others do have single quotes. Am I doing something wrong on the insert statement?
MY CODE:
<cfset productList="#pid#">
<cfloop list="#productList#" index="i">
<cfquery name="insertFlyerProducts" datasource="datasource">
insert into flyer_vendor_campaign_prod ucts (fid,pid,vendor_partno,sho rt_descrip tion,listp rice,disco unt,stndne t,promonet ,selling_u nit,vcode, pnew)
values (#fid#,#i#,'#vendor_partno #','#short _descripti on#',#list price#,#di scount#,#s tndnet#,#p romonet#,' #selling_u nit#','#vc ode#','#pn ew#')
</cfquery>
</cfloop>
ERROR:
Error Executing Database Query.
[Macromedia][SQLServer JDBC Driver][SQLServer]Incorrec t syntax near ','.
The error occurred in D:/Inetpub/URL.com/admin/v endors/add NewProduct .cfm: line 22
20 : <cfquery name="insertFlyerProducts" datasource="datasource">
21 : insert into flyer_vendor_campaign_prod ucts (fid,pid,vendor_partno,sho rt_descrip tion,listp rice,disco unt,stndne t,promonet ,selling_u nit,vcode, pnew)
22 : values (#fid#,#i#,'#vendor_partno #','#short _descripti on#',#list price#,#di scount#,#s tndnet#,#p romonet#,' #selling_u nit#','#vc ode#','#pn ew#')
23 : </cfquery>
24 : </cfloop>
MY CODE:
<cfset productList="#pid#">
<cfloop list="#productList#" index="i">
<cfquery name="insertFlyerProducts"
insert into flyer_vendor_campaign_prod
values (#fid#,#i#,'#vendor_partno
</cfquery>
</cfloop>
ERROR:
Error Executing Database Query.
[Macromedia][SQLServer JDBC Driver][SQLServer]Incorrec
The error occurred in D:/Inetpub/URL.com/admin/v
20 : <cfquery name="insertFlyerProducts"
21 : insert into flyer_vendor_campaign_prod
22 : values (#fid#,#i#,'#vendor_partno
23 : </cfquery>
24 : </cfloop>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Now I get the following error when trying to add an existing product and no error on a new product. It just doesn't add the item to the database,
[Macromedia][SQLServer JDBC Driver][SQLServer]Incorrec t syntax near ','.
The error occurred in D:/Inetpub/url/admin/vendo rs/addNewP roduct.cfm : line 22
20 : <cfquery name="insertFlyerProducts" datasource="mydatasource">
21 : insert into flyer_vendor_campaign_prod ucts (fid,pid,vendor_partno,sho rt_descrip tion,listp rice,disco unt,stndne t,promonet ,selling_u nit,vcode, pnew)
22 : values (#fid#,#i#,'#vendor_partno #','#short _descripti on#',#list price#,#di scount#,#s tndnet#,#p romonet#,' #selling_u nit#','#vc ode#','#pn ew#')
23 : </cfquery>
24 : </cfloop>
MY CODE:
<cfparam name="fid" default="">
<cfparam name="pid" default="">
<cfparam name="vendor_partno" default="0">
<cfparam name="short_description" default="0">
<cfparam name="listprice" default="">
<cfparam name="discount" default="">
<cfparam name="stndnet" default="">
<cfparam name="promonet" default="">
<cfparam name="selling_unit" default="">
<cfparam name="vcode" default="">
<cfparam name="pnew" default="">
<cfparam name="i" default="">
<cfparam name="productList" default="">
<cfparam name="productListArray" default="">
<cfif pnew is "no">
<cfset productList="#pid#">
<cfloop list="#productList#" index="i" delimiters = ",">
<cfquery name="insertFlyerProducts" datasource="mydatasource">
insert into flyer_vendor_campaign_prod ucts (fid,pid,vendor_partno,sho rt_descrip tion,listp rice,disco unt,stndne t,promonet ,selling_u nit,vcode, pnew)
values (#fid#,#i#,'#vendor_partno #','#short _descripti on#',#list price#,#di scount#,#s tndnet#,#p romonet#,' #selling_u nit#','#vc ode#','#pn ew#')
</cfquery>
</cfloop>
<cfelse>
<cfquery name="insertFlyerProducts" datasource="mydatasource">
insert into flyer_vendor_campaign_prod ucts (fid,pid,vendor_partno,sho rt_descrip tion,listp rice,disco unt,stndne t,promonet ,selling_u nit,vcode, pnew)
values (#fid#,#pid#,'#vendor_part no#','#sho rt_descrip tion#',#li stprice#,# discount#, #stndnet#, #promonet# ,'#selling _unit#','# vcode#','# pnew#')
</cfquery>
</cfif>
<cflocation url="flyer_step3.cfm?fid=# fid#&vcode =#vcode#">
[Macromedia][SQLServer JDBC Driver][SQLServer]Incorrec
The error occurred in D:/Inetpub/url/admin/vendo
20 : <cfquery name="insertFlyerProducts"
21 : insert into flyer_vendor_campaign_prod
22 : values (#fid#,#i#,'#vendor_partno
23 : </cfquery>
24 : </cfloop>
MY CODE:
<cfparam name="fid" default="">
<cfparam name="pid" default="">
<cfparam name="vendor_partno" default="0">
<cfparam name="short_description" default="0">
<cfparam name="listprice" default="">
<cfparam name="discount" default="">
<cfparam name="stndnet" default="">
<cfparam name="promonet" default="">
<cfparam name="selling_unit" default="">
<cfparam name="vcode" default="">
<cfparam name="pnew" default="">
<cfparam name="i" default="">
<cfparam name="productList" default="">
<cfparam name="productListArray" default="">
<cfif pnew is "no">
<cfset productList="#pid#">
<cfloop list="#productList#" index="i" delimiters = ",">
<cfquery name="insertFlyerProducts"
insert into flyer_vendor_campaign_prod
values (#fid#,#i#,'#vendor_partno
</cfquery>
</cfloop>
<cfelse>
<cfquery name="insertFlyerProducts"
insert into flyer_vendor_campaign_prod
values (#fid#,#pid#,'#vendor_part
</cfquery>
</cfif>
<cflocation url="flyer_step3.cfm?fid=#
ASKER
Weird. I completely changed the code and it is still happening.
<cfparam name="fid" default="">
<cfparam name="pid" default="">
<cfparam name="vendor_partno" default="0">
<cfparam name="short_description" default="0">
<cfparam name="listprice" default="">
<cfparam name="discount" default="">
<cfparam name="stndnet" default="">
<cfparam name="promonet" default="">
<cfparam name="selling_unit" default="">
<cfparam name="vcode" default="">
<cfparam name="pnew" default="">
<cfparam name="i" default="">
<cfparam name="productList" default="">
<cfparam name="productListArray" default="">
<cfset productList="#pid#">
<cfif pnew is "no">
<cfloop list="#productList#" index="i">
<cfquery name="getProducts" datasource="mydatasource">
select * fromproducts where pid = #i#
</cfquery>
<cfquery name="insertFlyerProducts" datasource="mydatasource">
insert into flyer_vendor_campaign_prod ucts (fid,pid,vendor_partno,sho rt_descrip tion,listp rice,disco unt,stndne t,promonet ,selling_u nit,vcode, pnew)
values (#fid#,#getProducts.pid#,' #getProduc ts.vendor_ partno#',' #getProduc ts.short_d escription #',#getPro ducts.list price#,#ge tProducts. discount#, #getProduc ts.stndnet #,#getProd ucts.promo net#,'#get Products.s elling_uni t#','#vcod e#','#pnew #')
</cfquery>
</cfloop>
<cfelseif pnew is "yes">
<cfquery name="insertFlyerProducts" datasource="mydatasource">
insert into flyer_vendor_campaign_prod ucts (fid,pid,vendor_partno,sho rt_descrip tion,listp rice,disco unt,stndne t,promonet ,selling_u nit,vcode, pnew)
values (#fid#,#pid#,'#vendor_part no#','#sho rt_descrip tion#',#li stprice#,# discount#, #stndnet#, #promonet# ,'#selling _unit#','# vcode#','# pnew#')
</cfquery>
</cfif>
<cflocation url="flyer_step3.cfm?fid=# fid#&vcode =#vcode#">
This is what the second query is trying to insert. It is a preexisting item.
VENDORERRORCODE 102
SQLSTATE HY000
SQL insert into flyer_vendor_campaign_prod ucts (fid,pid,vendor_partno,sho rt_descrip tion,listp rice,disco unt,stndne t,promonet ,selling_u nit,vcode, pnew) values (104,,'13','test',100,20,9 5,80,'ea', 'acs','yes ')
The code for a new item is:
<cfquery name="getLastVendorFlyer" datasource="mydatasource">
select * from flyer_vendor_campaigns where fid = #fid#
</cfquery>
<cfquery name="getLastPid" datasource="mydatasource" maxrows=1"">
select * from flyer_vendor_campaign_prod ucts where vcode = #vcode# order by pid desc
</cfquery>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Add Products</title>
<style type="text/css">
<!--
body,p,td,a {
font-family: "Trebuchet MS", Tahoma, Verdana, sans-serif;
font-size: 13px;
margin: 0;
padding: 0;
color: #666;
}
-->
</style>
</head>
<body>
<p> </p>
<table width="600" border="0" align="center" cellpadding="5" cellspacing="5">
<tr>
<td>
<p><img src="../../images/NISSCO.j pg" alt="Nissco RDG" /></p>
<p> </p>
<table border="0" cellspacing="4" cellpadding="4">
<tr>
<td valign="top"><strong>Item No.</strong></td>
<td valign="top"><strong>Descr iption</st rong></td>
<td valign="top"><strong>List Price</strong></td>
<td valign="top"><strong>Stnd Disc</strong></td>
<td valign="top"><strong>Stnd Net</strong></td>
<td valign="top"><strong>Promo Net</strong></td>
<td valign="top"><strong>Sell Unit</strong></td>
<td valign="top"><strong>ADD</ strong></t d>
</tr>
<cfoutput>
<cfform name="addProduct" action="addNewProduct.cfm? fid=#fid#& vcode=#vco de#" method="post" target="_top">
<cfinput type="hidden" name="vcode" value="#vcode#" />
<cfinput type="hidden" name="fid" value="#fid#" />
<cfinput type="hidden" name="pid" value="#evaluate(getLastPi d.pid + 1)#" />
<cfinput type="hidden" name="pnew" value="yes" />
<tr>
<td valign="top"><input type="text" size="10" name="vendor_partno" value="" /></td>
<td valign="top"><input type="text" size="65" name="short_description" value="" /></td>
<td valign="top"><input type="text" size="6" name="listprice" value="" /></td>
<td valign="top"><input type="text" size="6" name="discount" value="" /></td>
<td valign="top"><input type="text" size="6" name="stndnet" value="" /></td>
<td valign="top"><input type="text" size="6" name="promonet" value="" /></td>
<td valign="top"><input type="text" size="6" name="selling_unit" value="" /></td>
<td valign="top" colspan="8" align="center"><cfinput type="submit" name="submit" id="submit" value="add new"><br /><br /></td>
</tr>
</cfform>
</cfoutput>
</table>
</td>
</tr>
</table>
</body>
</html>
<cfparam name="fid" default="">
<cfparam name="pid" default="">
<cfparam name="vendor_partno" default="0">
<cfparam name="short_description" default="0">
<cfparam name="listprice" default="">
<cfparam name="discount" default="">
<cfparam name="stndnet" default="">
<cfparam name="promonet" default="">
<cfparam name="selling_unit" default="">
<cfparam name="vcode" default="">
<cfparam name="pnew" default="">
<cfparam name="i" default="">
<cfparam name="productList" default="">
<cfparam name="productListArray" default="">
<cfset productList="#pid#">
<cfif pnew is "no">
<cfloop list="#productList#" index="i">
<cfquery name="getProducts" datasource="mydatasource">
select * fromproducts where pid = #i#
</cfquery>
<cfquery name="insertFlyerProducts"
insert into flyer_vendor_campaign_prod
values (#fid#,#getProducts.pid#,'
</cfquery>
</cfloop>
<cfelseif pnew is "yes">
<cfquery name="insertFlyerProducts"
insert into flyer_vendor_campaign_prod
values (#fid#,#pid#,'#vendor_part
</cfquery>
</cfif>
<cflocation url="flyer_step3.cfm?fid=#
This is what the second query is trying to insert. It is a preexisting item.
VENDORERRORCODE 102
SQLSTATE HY000
SQL insert into flyer_vendor_campaign_prod
The code for a new item is:
<cfquery name="getLastVendorFlyer" datasource="mydatasource">
select * from flyer_vendor_campaigns where fid = #fid#
</cfquery>
<cfquery name="getLastPid" datasource="mydatasource" maxrows=1"">
select * from flyer_vendor_campaign_prod
</cfquery>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Add Products</title>
<style type="text/css">
<!--
body,p,td,a {
font-family: "Trebuchet MS", Tahoma, Verdana, sans-serif;
font-size: 13px;
margin: 0;
padding: 0;
color: #666;
}
-->
</style>
</head>
<body>
<p> </p>
<table width="600" border="0" align="center" cellpadding="5" cellspacing="5">
<tr>
<td>
<p><img src="../../images/NISSCO.j
<p> </p>
<table border="0" cellspacing="4" cellpadding="4">
<tr>
<td valign="top"><strong>Item No.</strong></td>
<td valign="top"><strong>Descr
<td valign="top"><strong>List Price</strong></td>
<td valign="top"><strong>Stnd Disc</strong></td>
<td valign="top"><strong>Stnd Net</strong></td>
<td valign="top"><strong>Promo
<td valign="top"><strong>Sell Unit</strong></td>
<td valign="top"><strong>ADD</
</tr>
<cfoutput>
<cfform name="addProduct" action="addNewProduct.cfm?
<cfinput type="hidden" name="vcode" value="#vcode#" />
<cfinput type="hidden" name="fid" value="#fid#" />
<cfinput type="hidden" name="pid" value="#evaluate(getLastPi
<cfinput type="hidden" name="pnew" value="yes" />
<tr>
<td valign="top"><input type="text" size="10" name="vendor_partno" value="" /></td>
<td valign="top"><input type="text" size="65" name="short_description" value="" /></td>
<td valign="top"><input type="text" size="6" name="listprice" value="" /></td>
<td valign="top"><input type="text" size="6" name="discount" value="" /></td>
<td valign="top"><input type="text" size="6" name="stndnet" value="" /></td>
<td valign="top"><input type="text" size="6" name="promonet" value="" /></td>
<td valign="top"><input type="text" size="6" name="selling_unit" value="" /></td>
<td valign="top" colspan="8" align="center"><cfinput type="submit" name="submit" id="submit" value="add new"><br /><br /></td>
</tr>
</cfform>
</cfoutput>
</table>
</td>
</tr>
</table>
</body>
</html>
ASKER
I did get the new products working, but my loop is not looping using the array or the list option. It is very strange. It tries to store all 3 products as one.
That looks like the exact same error from before ... what were the results of the debugging code I suggested??
This code just prints out the SQL being sent to the db: It's not supposed to insert anything.
Show ProductList First <cfdump var="#productList#">
<cfloop list="#productList#" index="i">
<!--- NO query tags here --->
Show SQL:
<cfoutput>
insert into flyer_vendor_campaign_prod ucts (fid,pid,vendor_partno,sho rt_descrip tion,listp rice,disco unt,stndne t,promonet ,selling_u nit,vcode, pnew)
values (#fid#,#i#,'#vendor_partno #','#short _descripti on#',#list price#,#di scount#,#s tndnet#,#p romonet#,' #selling_u nit#','#vc ode#','#pn ew#')
</cfoutput>
<br>
</cfloop>
This code just prints out the SQL being sent to the db: It's not supposed to insert anything.
Show ProductList First <cfdump var="#productList#">
<cfloop list="#productList#" index="i">
<!--- NO query tags here --->
Show SQL:
<cfoutput>
insert into flyer_vendor_campaign_prod
values (#fid#,#i#,'#vendor_partno
</cfoutput>
<br>
</cfloop>
ASKER
It's inserting this:
See what you're inserting.... - array
1 2
2 2
3 3
4 3
5 4
6 4
When it should only be 3 values. The 2,3,4. So it is doubling the code.
<cfset productList="#pid#">
<cfset productListArray = listToArray(productList,", ",false,tr ue)>
<cfdump var="#productListArray#" label="See what you're inserting....">
<cfoutput>#productListArra y#</cfoutp ut><cfabor t>
<cfloop list="#productList#" index="i">
<cfquery name="insertFlyerProducts" datasource="mydatasource">
insert into flyer_vendor_campaign_prod ucts (fid,pid,vendor_partno,sho rt_descrip tion,listp rice,disco unt,stndne t,promonet ,selling_u nit,vcode, pnew)
values (#fid#,#i#,'#vendor_partno #','#short _descripti on#',#list price#,#di scount#,#s tndnet#,#p romonet#,' #selling_u nit#','#vc ode#','#pn ew#')
</cfquery>
</cfloop>
...and it returns an error.
Complex object types cannot be converted to simple values.
The expression has requested a variable or an intermediate expression result as a simple value. However, the result cannot be converted to a simple value. Simple values are strings, numbers, boolean values, and date/time values. Queries, arrays, and COM objects are examples of complex values.
The most likely cause of the error is that you tried to use a complex value as a simple one. For example, you tried to use a query variable in a cfif tag.
The error occurred in D:/Inetpub/URL/admin/vendo rs/addNewP roduct.cfm : line 21
19 :
20 : <cfdump var="#productListArray#" label="See what you're inserting....">
21 : <cfoutput>#productListArra y#</cfoutp ut><cfabor t>
22 :
23 : <cfloop list="#productList#" index="i">
Why would it be duplicating? Could that be causing the error?
See what you're inserting.... - array
1 2
2 2
3 3
4 3
5 4
6 4
When it should only be 3 values. The 2,3,4. So it is doubling the code.
<cfset productList="#pid#">
<cfset productListArray = listToArray(productList,",
<cfdump var="#productListArray#" label="See what you're inserting....">
<cfoutput>#productListArra
<cfloop list="#productList#" index="i">
<cfquery name="insertFlyerProducts"
insert into flyer_vendor_campaign_prod
values (#fid#,#i#,'#vendor_partno
</cfquery>
</cfloop>
...and it returns an error.
Complex object types cannot be converted to simple values.
The expression has requested a variable or an intermediate expression result as a simple value. However, the result cannot be converted to a simple value. Simple values are strings, numbers, boolean values, and date/time values. Queries, arrays, and COM objects are examples of complex values.
The most likely cause of the error is that you tried to use a complex value as a simple one. For example, you tried to use a query variable in a cfif tag.
The error occurred in D:/Inetpub/URL/admin/vendo
19 :
20 : <cfdump var="#productListArray#" label="See what you're inserting....">
21 : <cfoutput>#productListArra
22 :
23 : <cfloop list="#productList#" index="i">
Why would it be duplicating? Could that be causing the error?
(Edit)
You're not running the exact code posted. Can you run it and post the results? Otherwise, if you're running completely different code we're going to keep going around in circles .. ;-)
> Complex object types cannot be converted to simple values.
That's an earlier version of some debugging code I posted - but you changed it and accidentally introduced an error. (I explained the reason for "complex object..." error here)
You're not running the exact code posted. Can you run it and post the results? Otherwise, if you're running completely different code we're going to keep going around in circles .. ;-)
> Complex object types cannot be converted to simple values.
That's an earlier version of some debugging code I posted - but you changed it and accidentally introduced an error. (I explained the reason for "complex object..." error here)
ASKER
Well, I had to change the code to even get the numbers to work correctly and it appears to be, but instead of looping the way it is supposed to, it duplicates it. What would be the best way to do this? Perhaps I am just doing it completely incorrectly.
It actually is the same code, the only change was I wasn't displaying the params and the else statement. Below is the original code that is producing the duplication and the complex value error. The only addition from my original post is the cfdump. Maybe I've been looking at the same piece of code too long.
<cfset productList="#pid#">
<cfset productListArray = listToArray(productList,", ",false,tr ue)>
<cfdump var="#productListArray#" label="See what you're inserting....">
<cfoutput>#productListArra y#</cfoutp ut><cfabor t>
<cfloop list="#productList#" index="i">
<cfquery name="insertFlyerProducts" datasource="nisscorest">
insert into flyer_vendor_campaign_prod ucts (fid,pid,vendor_partno,sho rt_descrip tion,listp rice,disco unt,stndne t,promonet ,selling_u nit,vcode, pnew)
values (#fid#,#i#,'#vendor_partno #','#short _descripti on#',#list price#,#di scount#,#s tndnet#,#p romonet#,' #selling_u nit#','#vc ode#','#pn ew#')
</cfquery>
It actually is the same code, the only change was I wasn't displaying the params and the else statement. Below is the original code that is producing the duplication and the complex value error. The only addition from my original post is the cfdump. Maybe I've been looking at the same piece of code too long.
<cfset productList="#pid#">
<cfset productListArray = listToArray(productList,",
<cfdump var="#productListArray#" label="See what you're inserting....">
<cfoutput>#productListArra
<cfloop list="#productList#" index="i">
<cfquery name="insertFlyerProducts"
insert into flyer_vendor_campaign_prod
values (#fid#,#i#,'#vendor_partno
</cfquery>
ASKER
I figured out the issue with the inserting of one value, but I have 5 values from one form that need to be inserted using check boxes for the identity. So the form looks like this:
<table border="0" cellspacing="4" cellpadding="4">
<tr>
<td valign="top">INCL.</td>
<td valign="top"><strong>Item No.</strong></td>
<td valign="top"><strong>Descr iption</st rong></td>
<td valign="top"><strong>List Price</strong></td>
<td valign="top"><strong>Stnd Disc</strong></td>
<td valign="top"><strong>Stnd Net</strong></td>
<td valign="top"><strong>Promo Net</strong></td>
<td valign="top"><strong>Sell Unit</strong></td>
</tr>
<cfoutput>
<cfform name="addProduct" action="addExistingProduct s.cfm?fid= #fid#&vcod e=#vcode#& pnew=no" method="post" target="_top">
<cfloop query="getProducts">
<cfinput type="hidden" name="vcode" value="#vcode#" />
<cfinput type="hidden" name="fid" value="#fid#" />
<cfinput type="hidden" name="pnew" value="no" />
<tr>
<td valign="top"><input type="checkbox" size="10" name="pid" value="#productid#" /></td>
<td valign="top"><input type="text" size="10" name="vendor_partno" value="#item_number#" readonly /></td>
<td valign="top"><input type="text" size="65" name="short_description" value="#short_description# " readonly /></td>
<td valign="top"><input type="text" size="6" name="listprice" value="#list_price#" readonly /></td>
<td valign="top"><input type="text" size="6" name="discount" value="" /></td>
<td valign="top"><input type="text" size="6" name="stndnet" value="" /></td>
<td valign="top"><input type="text" size="6" name="promonet" value="#dealer_net_sale#" /></td>
<td valign="top"><input type="text" size="6" name="selling_unit" value="#selling_unit#" /></td>
</tr>
</cfloop>
<tr>
<td valign="top" colspan="8" align="center"><cfinput type="submit" name="submit" id="submit" value="add selected products"><br /><br /></td>
</tr>
</cfform>
</cfoutput>
</table>
Processing Page:
<cfset productList="#pid#">
<cfset discountList="#discount#">
<cfset stndnetList="#stndnet#">
<cfset promonetList="#promonet#">
<cfset selling_unitList="#selling _unit#">
<cfset productLength = "#ListLen(productList)#">
<cfloop list="#productList#" index="i">
<cfquery name="getFlyerProducts" datasource="mydatasource">
select * from products where productid = #i#
</cfquery>
<cfquery name="insertFlyerProducts" datasource="mydatasource">
insert into flyer_vendor_campaign_prod ucts (fid,pid,vendor_partno,sho rt_descrip tion,listp rice,disco unt,stndne t,promonet ,selling_u nit,vcode, pnew)
values (#fid#,#i#,'#getFlyerProdu cts.item_n umber#','# getFlyerPr oducts.sho rt_descrip tion#',#ge tFlyerProd ucts.list_ price#,#di scount#,#s tndnet#,#p romonet#,' #selling_u nit#','#vc ode#','#pn ew#')
</cfquery>
<cfloop list="#discountList#" index="d">
<cfquery name="insertFlyerDiscount" datasource="mydatasource">
update flyer_vendor_campaign_prod ucts
set discount = #d# where fid = #fid# and pid = #i#
</cfquery>
</cfloop>
<cfloop list="#stndnetList#" index="s">
<cfquery name="insertFlyerNet" datasource="mydatasource">
update flyer_vendor_campaign_prod ucts
set stndnet = #s# where fid = #fid# and pid = #i#
</cfquery>
</cfloop>
<cfloop list="#promonetList#" index="p">
<cfquery name="insertFlyerPromo" datasource="mydatasource">
update flyer_vendor_campaign_prod ucts
set promonet = #p# where fid = #fid# and pid = #i#
</cfquery>
</cfloop>
<cfloop list="#selling_unitList#" index="u">
<cfquery name="insertFlyerUnit" datasource="mydatasource">
update flyer_vendor_campaign_prod ucts
set selling_unit = '#u#' where fid = #fid# and pid = #i#
</cfquery>
</cfloop>
</cfloop>
It works! Eureka! Thank you experts! :)
<table border="0" cellspacing="4" cellpadding="4">
<tr>
<td valign="top">INCL.</td>
<td valign="top"><strong>Item No.</strong></td>
<td valign="top"><strong>Descr
<td valign="top"><strong>List Price</strong></td>
<td valign="top"><strong>Stnd Disc</strong></td>
<td valign="top"><strong>Stnd Net</strong></td>
<td valign="top"><strong>Promo
<td valign="top"><strong>Sell Unit</strong></td>
</tr>
<cfoutput>
<cfform name="addProduct" action="addExistingProduct
<cfloop query="getProducts">
<cfinput type="hidden" name="vcode" value="#vcode#" />
<cfinput type="hidden" name="fid" value="#fid#" />
<cfinput type="hidden" name="pnew" value="no" />
<tr>
<td valign="top"><input type="checkbox" size="10" name="pid" value="#productid#" /></td>
<td valign="top"><input type="text" size="10" name="vendor_partno" value="#item_number#" readonly /></td>
<td valign="top"><input type="text" size="65" name="short_description" value="#short_description#
<td valign="top"><input type="text" size="6" name="listprice" value="#list_price#" readonly /></td>
<td valign="top"><input type="text" size="6" name="discount" value="" /></td>
<td valign="top"><input type="text" size="6" name="stndnet" value="" /></td>
<td valign="top"><input type="text" size="6" name="promonet" value="#dealer_net_sale#" /></td>
<td valign="top"><input type="text" size="6" name="selling_unit" value="#selling_unit#" /></td>
</tr>
</cfloop>
<tr>
<td valign="top" colspan="8" align="center"><cfinput type="submit" name="submit" id="submit" value="add selected products"><br /><br /></td>
</tr>
</cfform>
</cfoutput>
</table>
Processing Page:
<cfset productList="#pid#">
<cfset discountList="#discount#">
<cfset stndnetList="#stndnet#">
<cfset promonetList="#promonet#">
<cfset selling_unitList="#selling
<cfset productLength = "#ListLen(productList)#">
<cfloop list="#productList#" index="i">
<cfquery name="getFlyerProducts" datasource="mydatasource">
select * from products where productid = #i#
</cfquery>
<cfquery name="insertFlyerProducts"
insert into flyer_vendor_campaign_prod
values (#fid#,#i#,'#getFlyerProdu
</cfquery>
<cfloop list="#discountList#" index="d">
<cfquery name="insertFlyerDiscount"
update flyer_vendor_campaign_prod
set discount = #d# where fid = #fid# and pid = #i#
</cfquery>
</cfloop>
<cfloop list="#stndnetList#" index="s">
<cfquery name="insertFlyerNet" datasource="mydatasource">
update flyer_vendor_campaign_prod
set stndnet = #s# where fid = #fid# and pid = #i#
</cfquery>
</cfloop>
<cfloop list="#promonetList#" index="p">
<cfquery name="insertFlyerPromo" datasource="mydatasource">
update flyer_vendor_campaign_prod
set promonet = #p# where fid = #fid# and pid = #i#
</cfquery>
</cfloop>
<cfloop list="#selling_unitList#" index="u">
<cfquery name="insertFlyerUnit" datasource="mydatasource">
update flyer_vendor_campaign_prod
set selling_unit = '#u#' where fid = #fid# and pid = #i#
</cfquery>
</cfloop>
</cfloop>
It works! Eureka! Thank you experts! :)
ASKER
Thank you for your patience and assistance. I wouldn't have been able to do this without you. You rock! :)
1. Which value is the item number : #i#?
2. What are the actual values in the array?
3. What's the data type of the "PID" column?
Side note, you should always use cfqueryparam. Especially when looping, because it can improve performance when running the same query over and over. Plus it solves a lot of data conversion issues, and more important protects against sql injection.