Hello again group. I've been stareing at this for ages trying to figure out why it's not working, I can't see why it's not.
Am I blind? I think my trouble is in the very last section. What I'm trying to do is when a user hits "back" after clicking an item to put in his/her cart, the button is still visable and functional from before, until they hit refresh, or the page automatically refreshes, so they can actually hit it again and buy the same item they just bought TWICE. I can't have this, so I'm trying to check the current state of the database and make sure that they have not attempted to put an item into their cart that is already in someone's cart (likely their own). Each product is unique, so there will never be a case of a user needing duplicate items. A "1" value in the "sold" field indicates that the product HAS BEEN sold. I hope I'm being clear. I hope someone can help. I thank you in advance. -Dave use CGI; use DBI; $addtocart_co = new CGI; $dbh = DBI->connect('dbi:ODBC:gallery'); $dbh2 = DBI->connect('dbi:ODBC:gallery'); $pid = $addtocart_co->param("selected"); $sqlstatement = "UPDATE gallery SET sold = '1' WHERE pid = $pid"; $sth = $dbh->prepare($sqlstatement); $sth->execute || die "Could not execute SQL statement ... maybe invalid?"; ##COMMENT #if(0) #{ $sqlstatement2 = "SELECT pid, sold FROM gallery ORDER BY pid"; $sth2 = $dbh2->prepare($sqlstatement2); $sth2->execute || die "Could not execute SQL statement ... maybe invalid?"; #} ##Need code to check if product has been added already. (Getting duplicate pids in my cookies) $pidsincart = $addtocart_co->cookie(-name=>'incart'); $cookie = $addtocart_co->cookie(-name=>'incart', -value=>" " . $pid . ":" . $pidsincart . " ", -expires=>'+1h'); print $addtocart_co->header(-cookie=>$cookie); print qq~<LINK HREF="/wholesalegallery/wg.css" REL="stylesheet" TYPE="text/css">\n~; print qq~<HTML>\n~; print qq~<BODY background="../../../../wholesalegallery/weave-gr.jpg">\n~; ##COMMENT #if(0) #{ $done = 0; while (@row=$sth2->fetchrow_array) { if (($row[0] == $pid) && ($row[1] == 1) && ($done == 0)) { print qq~Product has been sold already, select a different product.\n~; print qq~</BODY>\n~; print qq~</HTML>\n~; $done = 1; } if ($done == 0) { print qq~Item $pid has been placed in your shopping cart. <A HREF = "/cgi-bin/viewcart.pl">CLICK HERE TO VIEW CART CONTENTS</A>\n~; print qq~</BODY>\n~; print qq~</HTML>\n~; $done = 1; } } #}