Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing URL variables uniquely 3

Status
Not open for further replies.

fusionaire

Programmer
May 20, 2000
67
US
I have a shopping cart application in which I pass variable values through URL's. The problem is, if someone selects the same product again, it will show up twice on the &quot;items selected&quot; screen. When the user goes to eliminate one of the two already selected products, information on both are deleted from the database.<br><br>So, I have tried to come up with a way to uniquely identify an already inserted product in the database.Here is the code for that:<br><br>&lt;CFQUERY name=&quot;prod&quot; datasource=&quot;wpslive&quot;&gt;<br>SELECT PRODUCT_ID, ORDERNUMBER AS REDUNDANTITEM<br>FROM orders<br>WHERE&nbsp;&nbsp;ORDERNUMBER='#session.cid#'<br>&lt;/cfquery&gt;<br><br>&lt;cfoutput query=&quot;prod&quot;&gt;<br>&lt;input type=&quot;hidden&quot; name=&quot;REDUNDANTITEM&quot; value=&quot;#prod.REDUNDANTITEM#&quot;&gt;<br>&lt;/cfoutput&gt;<br><br> <br>&lt;CFIF IsDefined (&quot;prod.REDUNDANTITEM&quot;)&gt;<br><br>&lt;CFLOCATION URL =&quot;alreadyordered.cfm&quot; ADDTOKEN=&quot;no&quot;&gt;<br>&lt;/cfif&gt;<br><br>When I use this code, anytime I select any product, the CFLOCATION kicks in and the user is told that they have already entered the chosen product already. <br><br>If anyone knows a better way to do this, I'd very much appreciate it.<br><br>PS~Special thanks to Darkman, who seems to know the answer to everything!
 
with that piece of code the only reason i see why the quantity would remain the same is that the form.quantity value is always the same (so the error is NOT in the page you're looking in ;))<br>
 
I GOT IT!!!<br><br>I tries a couple of things, and I changed the attributes of my query and now it works.<br><br>Special thanks to both Iza and DarkMan for all of thier help.
 
Just curious, as I was about to post one more suggestion.<br><br>Did you add the Product_ID and Quantity to the WHERE clause in the initial select query?
 
dark, if the quantity was in the initial select query, don't you think it'll b possible for the same user to select twice the SAME product as long as he doesn't choose the same quantity of that product ?? well, it depends on what fusionaire wants the user to be able to do - or not ...
 
Here is the latest and greatest code that I use:<br><br>&lt;CFQUERY name=&quot;prod&quot; datasource=&quot;wpslive&quot;&gt;<br>SELECT PRODUCT_ID, ORDERNUMBER AS REDUNDANTITEM<br>FROM orders<br>WHERE&nbsp;&nbsp;ORDERNUMBER='#session.cid#' AND PRODUCT_ID='#FORM.PRODUCT_ID#' <br>&lt;/cfquery&gt;<br><br>&lt;cfoutput query=&quot;prod&quot;&gt;<br>&lt;input type=&quot;hidden&quot; name=&quot;REDUNDANTITEM&quot; value=&quot;#prod.REDUNDANTITEM#&quot;&gt;<br>&lt;/cfoutput&gt;<br><br>&lt;cfif prod.recordcount gt 0&gt;<br>&nbsp;&nbsp;&lt;!---- means you've already have it inserted ! ---&gt;<br>&nbsp;&nbsp;&lt;CFLOCATION URL =&quot;dumkoff.cfm&quot; ADDTOKEN=&quot;no&quot;&gt;<br>&lt;cfelse&gt;<br>&nbsp;&nbsp;&lt;!--- it's the 1st time you got that productid AND oredernb ---&gt;<br>&nbsp;&nbsp;&lt;cfinsert datasource=&quot;wpslive&quot;<br> tablename=&quot;orders&quot;<br> formfields=&quot;ORDERNUMBER, PRODUCT_ID, MFG, PRICE, QUANTITY, DESCRIPTION&quot;&gt;<br><br><br>&lt;CFQUERY name=&quot;detail&quot; datasource=&quot;wpslive&quot;&gt;<br>SELECT PRICE, QUANTITY, PRODUCT_ID, MFG, DESCRIPTION, ORDERNUMBER, (price * quantity) AS TOTALPRICE<br>FROM orders<br>WHERE&nbsp;&nbsp;PRODUCT_ID='#FORM.PRODUCT_ID#' <br>&lt;/cfquery&gt;<br>&lt;/cfif&gt;<br>I changed the &quot;detail&quot; query Where clause....<br><br>Thanks again to both of you for all the help!
 
<div align=center><b><i><font color=red>EXCELLENT!</font></i></b></div><br><br>Good luck with the rest of your program, and have a great weekend!<br><br>DM
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top