A more efficient way would be (provided you're using enterprise-grade DBMS):
<cfquery datasource="test_shop">
if not exists
(SELECT *
FROM orders
WHERE PRODUCTID = {cfqueryparam...})
begin
INSERT INTO orders (productID)
VALUES ({cfqueryparam...})
end
</cfquery>
>Hi:
>I want the user to add products into the order table but I don't want it to
>add the same product two or more times into the table.
>I made a condition and for a test I used ProductID s and I put them in the
>condition myself just to test it.
>If I enter the same productID which is in the table it works fine but when I
>enter the second record it doesn't work at all!. I think it may need to be
>looped but have no idea how to that.
>Please please help me. <cfif conditional.ProductID EQ 2> here 2 is the
>second productID which IS in my database but still it enters data into the
>database while it shouldn't!
>this is my code
>
><cfquery name="conditional" datasource="test_shop">
> SELECT *
> FROM orders
></cfquery>
>
> <cfif conditional.ProductID EQ 2>
>
>It's not possible to add the same product.
>
> <cfelse>
>
><cfquery datasource="Test_Shop">
> INSERT INTO orders (productID)
> VALUES ("#FORM.addme#")
></cfquery>
>Thanks for inserting new product
> </cfif>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to
date
Get the Free Trial
http://ad.doubleclick.net/clk;160198600;22374440;w
Archive:
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:298558
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4