JLitkie Posted July 6, 2010 Share Posted July 6, 2010 I am building a shopping cart from ground up and I am having a problem with the products being reentered into the DB. I need help trying to stop it from being entered twice when refreshed. <?xml version="1.0" encoding="UTF-8"?> <!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" xml:lang="en" lang="en"> <head> <title>Tickle Creek Candles</title> <meta http-equiv="generator" content="CoffeeCup HTML Editor (www.coffeecup.com)" /> <meta name="created" content="Tue, 22 Jun 2010 22:09:16 GMT" /> <meta name="description" content="" /> <meta name="keywords" content="" /> <style type="text/css"> <!-- /* Don't underline links */ a:link {text-decoration: none;} a:visited {text-decoration: none;} --> </style> <script type="text/javascript" src="jquery.min.js"></script> <script type="text/javascript" src="ddaccordion.js"> /*********************************************** * Accordion Content script- (c) Dynamic Drive DHTML code library (www.dynamicdrive.com) * Visit http://www.dynamicDrive.com for hundreds of DHTML scripts * This notice must stay intact for legal use ***********************************************/ </script> <script type="text/javascript"> ddaccordion.init({ headerclass: "expandable", //Shared CSS class name of headers group that are expandable contentclass: "categoryitems", //Shared CSS class name of contents group revealtype: "click", //Reveal content when user clicks or onmouseover the header? Valid value: "click", "clickgo", or "mouseover" mouseoverdelay: 200, //if revealtype="mouseover", set delay in milliseconds before header expands onMouseover collapseprev: true, //Collapse previous content (so only one open at any time)? true/false defaultexpanded: [0], //index of content(s) open by default [index1, index2, etc]. [] denotes no content onemustopen: false, //Specify whether at least one header should be open always (so never all headers closed) animatedefault: false, //Should contents open by default be animated into view? persiststate: true, //persist state of opened contents within browser session? toggleclass: ["", "openheader"], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"] togglehtml: ["prefix", "", ""], //Additional HTML added to the header when it's collapsed and expanded, respectively ["position", "html1", "html2"] (see docs) animatespeed: "fast", //speed of animation: integer in milliseconds (ie: 200), or keywords "fast", "normal", or "slow" oninit:function(headers, expandedindices){ //custom code to run when headers have initalized //do nothing }, onopenclose:function(header, index, state, isuseractivated){ //custom code to run whenever a header is opened or closed //do nothing } }) </script> <style type="text/css"> .arrowlistmenu{ width: 100%; /*width of accordion menu*/ } .arrowlistmenu .menuheader{ /*CSS class for menu headers in general (expanding or not!)*/ font: bold 14px Arial; color: White; background: black url(Graphics/titlebar.png) repeat-x center left; margin-bottom: 10px; /*bottom spacing between header and rest of content*/ text-transform: uppercase; padding: 4px 0 4px 10px; /*header text is indented 10px*/ cursor: hand; cursor: pointer; } .arrowlistmenu .openheader{ /*CSS class to apply to expandable header when it's expanded*/ background-image: url(Graphics/titlebar-active.png); } .arrowlistmenu ul{ /*CSS for UL of each sub menu*/ list-style-type: none; margin: 0; padding: 0; margin-bottom: 8px; /*bottom spacing between each UL and rest of content*/ } .arrowlistmenu ul li{ padding-bottom: 2px; /*bottom spacing between menu items*/ } .arrowlistmenu ul li a{ color: #FFFFFF; display: block; padding: 2px 0; padding-left: 19px; /*link text is indented 19px*/ text-decoration: none; font-weight: bold; border-bottom: 0px solid #dadada; font-size: 100%; } .arrowlistmenu ul li a:visited{ color: #FFFFFF; } .arrowlistmenu ul li a:hover{ /*hover state CSS*/ color: #FF0000; background-color: #400000; } </style> <?php session_start(); ?> </head> <body bgcolor="#FFFFFF" text="#FFFFFF" link="#FFFFFF" vlink="#FFFFFF" alink="#FF0000" background="Graphics/wood018.jpg"> <div id="1" style="height:23%;width:15%;position:absolute;top:0%;left:10%;background-color:#400000;border-left:solid;"> <img src="Graphics/Logo.jpg" width="100%" height="100%" alt="" title="" border="0" align="" /> </div> <div id="2" style="height:12%;width:65%;position:absolute;top:0%;left:25%;background-color:#400000;text-indent:2%;border-right:solid;border-left:solid;"> <font size="7" face="AR ESSENCE"><b><u>Tickle Creek Candles</u></b></font> </div> <div id="3" style="height:6%;width:65%;position:absolute;top:12%;left:25%;background-color:#400000;text-indent:2%;border-right:solid;border-left:solid;"> <font size="5" face="AR ESSENCE"><b>Hand Made Candles</b></font> </div> <div id="4" style="min-height:77%;width:15%;position:absolute;top:23%;left:10%;background-color:#400000;text-indent:2%;border-left:solid;"> <font size="6" face="AR ESSENCE"><u><b><center>Contents</center></b></u></font> <div class="arrowlistmenu"> <h3 class="menuheader" style="cursor: default"><a href="Index.php">Home</a></h3> <h3 class="menuheader expandable">Products</h3> <ul class="categoryitems"> <li><a href="Pies.php">PIES</a></li> <li><a href="Bakery.php">BAKERY GOODS</a></li> <li><a href="Containers.php">CONTAINERS</a></li> <li><a href="Melts.php">MELTS</a></li> <li><a href="Warmers.php">WARMERS</a></li> </ul> <h3 class="menuheader" style="cursor: default"><a href="About.php">About Us</a></h3> <h3 class="menuheader" style="cursor: default"><a href="Contact.php">Contact Us</a></h3> </div> </div> <div id="5" style="min-height:82%;width:65%;position:absolute;top:18%;left:25%;background-color:#400000;border-right:solid;border-left:solid;border-top:solid;"> <br /> <font size="6" face="AR ESSENCE"> <b>Shopping Cart</b> </font> <br /><br /> <?php $_SESSION['Identifier'] = session_id(); $Identifier = $_SESSION['Identifier']; $ID = $_POST['ID']; $cat = $_POST['cat']; $Code = $_POST['Price']; include("database.php"); mysql_select_db("tc", $con); $result = mysql_query("SELECT * FROM Pricing WHERE Code='$Code'"); while($row = mysql_fetch_array($result)) { $Price = $row[2]; } $result = mysql_query("SELECT * FROM Products WHERE ID='$ID'"); while($row = mysql_fetch_array($result)) { $SKU = $row[0]; $Name = $row[1]; $QDesc = $row[2]; $Desc = $row[3]; $Price = $row[4]; $Cat = $row[5]; $Cost = $row[6]; $Qty = $row[7]; $Pic = $row[8]; $Opt1 = $row[9]; $Opt2= $row[10]; $Opt3 = $row[11]; } $result = mysql_query("SELECT * FROM shopping_cart WHERE Identifier='$Identifier'"); while($row = mysql_fetch_array($result)) { If((isset($SKU2)) == FALSE) { $SKU2 = $row[3]; } ELSE { } } IF($SKU2 == $SKU) { } Else { include("database.php"); mysql_select_db("tc", $con); $sql = "INSERT INTO shopping_cart (Identifier) VALUES ('$Identifier')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } $sql = "UPDATE shopping_cart SET Product='$Name', SKU='$SKU', Quantity='1', Price='$Price', PicAddress='$Pic' WHERE Identifier='$Identifier' AND Product=''"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } } print "<table border='0' width='95%' align='center'>"; print "<tr><!-- Row 1 --> <td width='10%'><b><u>DELETE</u></b></td><!-- Col 1 --> <td width='45%' colspan='2'><b><u>PRODUCT</u></b></td><!-- Col 2 --> <td width='15%'><b><u>QUANTITY</u></b></td><!-- Col 4 --> <td width='15%' align='right'><b><u>PRICE</u></b></td><!-- Col 5 --> <td width='15%' align='right'><b><u>TOTAL</u></b></td><!-- Col 6 --> </tr>"; include("database.php"); mysql_select_db("tc", $con); $result = mysql_query("SELECT * FROM shopping_cart WHERE Identifier= '$Identifier'"); while($row = mysql_fetch_array($result)) { echo "<tr><!-- Row 2 --> <td width='10%' valign='middle'><center><input type='checkbox' name='Delete' value='$row[0]'></center></td><!-- Col 1 --> <td width='15%'><img src='$row[10]' width='100%' height='100%' alt='' border='1'></td><!-- Col 2 --> <td width='30%' valign='top'>$row[2]</td><!-- Col 3 --> <td width='15%' valign='top'><input type='text' name='Quantity' value='$row[4]' size='10' style='background-color:#400000;border:none;color:#FFFFFF;text-align:right;'></td><!-- Col 4 --> <td width='15%' valign='top' align='right'><input type='text' name='Price' value='$$row[5]' size='10' style='background-color:#400000;border:none;color:#FFFFFF;text-align:right;'></td><!-- Col 5 --> <td width='15%' valign='top' align='right'><b>"; $sub = $row[4] * $row[5]; echo "$$sub</b></td><!-- Col 6 --> </tr>"; } print "<tr><!-- Row 3 --> <td width='85%' colspan='5' align='right' style='border-top:solid;'><b>SUB TOTAL</b></td><!-- Col 1 --> <td width='15%' align='right' style='border-top:solid;'><b>$</b>"; echo "</td><!-- Col 6 --> </tr> <tr><!-- Row 4 --> <td width='85%' colspan='5' align='right'><b>TAXES</b></td><!-- Col 1 --> <td width='15%' align='right'><b></b></td><!-- Col 6 --> </tr> <tr><!-- Row 5 --> <td width='85%' colspan='5' align='right'><b>SHIPPING</b></td><!-- Col 1 --> <td width='15%' align='right'><b>$</b></td><!-- Col 6 --> </tr> <tr><!-- Row 6 --> <td width='85%' colspan='5' align='right'><b>GRAND TOTAL</b></td><!-- Col 1 --> <td width='15%' align='right'><b>$</b></td><!-- Col 6 --> </tr> <tr><!-- Row 6 --> <td width='70%' colspan='4' align='right'><br /><input type='submit' name='submit' value='UPDATE SHOPPING CART'></td><!-- Col 1 --> <td width='30%' colspan='2' align='right'><br /><input type='submit' name='submit' value='CONTINUE PURCHASE'></td><!-- Col 6 --> </tr> </table>"; ?> </div> </body> </html> Link to comment https://forums.phpfreaks.com/topic/206846-trouble-with-replication-on-reload/ Share on other sites More sharing options...
bodycount Posted July 6, 2010 Share Posted July 6, 2010 I do the following to stop duplicate serialnumbers being entered into my database // duplicate entry $sql="SELECT * FROM products WHERE SERIALNO='$SERIALNO'"; $mysql_result=mysql_query($sql) or die(mysql_error()); $num_rows=mysql_num_rows($mysql_result); if ( $num_rows == 0) { echo "<br>"; echo "No Duplicates Found"; $query = ("INSERT INTO `products` (`SERIALNO`, `IMEI`, `CANSERIAL`, `DESCRIPTION`, `SHIPDATE`, `CANTYPE`, `COMPANY_id`, `BUILDTYPE`, `MACADDRESS`, `BOARD_REV`, `BOARDTYPE`, `COMMENTS`, `ADVICENOTE` ,`BOXPRODUCT_id`,`CANFIRMWARE`,`ROHS`,`BOARDFIRM`,`MSC_id`,`PLDPROG`,`BOOTPROG`,`FRTYPE`) VALUES ('$SERIALNO','$IMEI','$CANSERIAL', '$DESCRIPTION', '$SHIPDATE','$CANTYPE','$COMPANY_id','$BUILDTYPE','$MACADDRESS' ,'$BOARD_REV' ,'$BOARDTYPE' ,'$COMMENTS' ,'$ADVICENOTE' ,'$BOXPRODUCT_id','$CANFIRMWARE','$ROHS','$BOARDFIRM','$MSC_id','$PLDPROG','$BOOTPROG','$FRTYPE')"); $result = mysql_query($query) or die ("<br>Error in query: ".mysql_error()); } else { echo "<script type=\"text/javascript\">alert('Entry Not entered into database the Serial No. Already exists in the database.')</script>"; } I hope it helps Link to comment https://forums.phpfreaks.com/topic/206846-trouble-with-replication-on-reload/#findComment-1081816 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.