ohno Posted January 13, 2014 Share Posted January 13, 2014 Many moons ago we had a custom cart written, works great but I need to make some changes, just can't seem to get them to work! There is a file called data.php which has this code :- case 20: //Displays the add to cart form & cross selling info. Requires product ID $sql = "SELECT code FROM products WHERE productid='".mysql_real_escape_string($_GET['id'])."'"; $result = mysql_query($sql); while ( $row = @mysql_fetch_array($result, MYSQL_BOTH) ) { $data = '<font size="2" face="Verdana, Arial, Helvetica, sans-serif"color="#000000"><form method="post" action="https://www.domain.co.uk/s_addtocart.php" target="_blank"><input type="hidden" name="code" value="'.$row['code'].'" /><input type="image" src="images/add.gif" name="Submit" alt="Add To Cart" style="vertical-align:middle; border: none;" />Quantity: <input type="text" name="quantity" size="3" value="1" /></form></font>'; } //Displays cross selling information. Requires product ID $xprods = array(); $sql = "SELECT xselling.xproductid FROM xselling, products WHERE xselling.xproductid=products.productid AND xselling.active='1' AND products.active='1' AND products.live='1' AND xselling.productid='".mysql_real_escape_string($_GET['id'])."'"; $result = mysql_query($sql); while ( $row = @mysql_fetch_array($result, MYSQL_BOTH) ) { array_push($xprods, $row['xproductid']); } if ( (count($xprods) <= 4) && (count($xprods) > 0) ) { $a = 0; $b = count($xprods); while ( $a < $b ) { $sql = "SELECT code, title, img, url, price FROM products WHERE active='1' AND live='1' AND productid='".$xprods[$a]."'"; $result = mysql_query($sql); switch ($a) { case 0: $row = mysql_fetch_assoc($result); $x1 = '<a href="'.$producturl.$row['url'].'" style="color:#0000FF;"><img src="'.$imageurl.$row['img'].'" border="none" alt="'.$row['title'].'" /><br />'.$row['title'].'</a>'; $x1a = '£'.$row['price']; $x1b = '<form method="post" action="https://www.domain.co.uk/s_quickadd.php" target="_blank"><input type="hidden" name="code" value="'.$row['code'].'" /><input type="image" src="images/add.gif" name="Submit" alt="Add To Cart" /></form>'; break; case 1: $row = mysql_fetch_assoc($result); $x2 = '<a href="'.$producturl.$row['url'].'" style="color:#0000FF;"><img src="'.$imageurl.$row['img'].'" border="none" alt="'.$row['title'].'" /><br />'.$row['title'].'</a>'; $x2a = '£'.$row['price']; $x2b = '<form method="post" action="https://www.domain.co.uk/s_quickadd.php" target="_blank"><input type="hidden" name="code" value="'.$row['code'].'" /><input type="image" src="images/add.gif" name="Submit" alt="Add To Cart" /></form>'; break; case 2: $row = mysql_fetch_assoc($result); $x3 = '<a href="'.$producturl.$row['url'].'" style="color:#0000FF;"><img src="'.$imageurl.$row['img'].'" border="none" alt="'.$row['title'].'" /><br />'.$row['title'].'</a>'; $x3a = '£'.$row['price']; $x3b = '<form method="post" action="https://www.domain.co.uk/s_quickadd.php" target="_blank"><input type="hidden" name="code" value="'.$row['code'].'" /><input type="image" src="images/add.gif" name="Submit" alt="Add To Cart" /></form>'; break; case 3: $row = mysql_fetch_assoc($result); $x4 = '<a href="'.$producturl.$row['url'].'" style="color:#0000FF;"><img src="'.$imageurl.$row['img'].'" border="none" alt="'.$row['title'].'" /><br />'.$row['title'].'</a>'; $x4a = '£'.$row['price']; $x4b = '<form method="post" action="https://www.domain.co.uk/s_quickadd.php" target="_blank"><input type="hidden" name="code" value="'.$row['code'].'" /><input type="image" src="images/add.gif" name="Submit" alt="Add To Cart" /></form>'; break; } $a++; } } elseif ( count($xprods) > 4 ) { $c = 0; while ( $c < 4 ) { $pick = rand(1,count($xprods)); $pick = $pick - 1; switch ($c) { case 0: $x1 = $xprods[$pick]; break; case 1: $x2 = $xprods[$pick]; break; case 2: $x3 = $xprods[$pick]; break; case 3: $x4 = $xprods[$pick]; break; } unset($xprods[$pick]); $xprods = array_values($xprods); $c++; } $sql = "SELECT code, title, img, url, price FROM products WHERE active='1' AND live='1' AND productid='".$x1."'"; $result = mysql_query($sql); while ( $row = @mysql_fetch_array($result, MYSQL_BOTH) ) { $x1 = '<a href="'.$producturl.$row['url'].'" style="color:#0000FF;"><img src="'.$imageurl.$row['img'].'" border="none" alt="'.$row['title'].'" /><br />'.$row['title'].'</a>'; $x1a = '£'.$row['price']; $x1b = '<form method="post" action="https://www.domain.co.uk/s_quickadd.php" target="_blank"><input type="hidden" name="code" value="'.$row['code'].'" /><input type="image" src="images/add.gif" name="Submit" alt="Add To Cart" /></form>'; } $sql = "SELECT code, title, img, url, price FROM products WHERE active='1' AND live='1' AND productid='".$x2."'"; $result = mysql_query($sql); while ( $row = @mysql_fetch_array($result, MYSQL_BOTH) ) { $x2 = '<a href="'.$producturl.$row['url'].'" style="color:#0000FF;"><img src="'.$imageurl.$row['img'].'" border="none" alt="'.$row['title'].'" /><br />'.$row['title'].'</a>'; $x2a = '£'.$row['price']; $x2b = '<form method="post" action="https://www.domain.co.uk/s_quickadd.php" target="_blank"><input type="hidden" name="code" value="'.$row['code'].'" /><input type="image" src="images/add.gif" name="Submit" alt="Add To Cart" /></form>'; } $sql = "SELECT code, title, img, url, price FROM products WHERE active='1' AND live='1' AND productid='".$x3."'"; $result = mysql_query($sql); while ( $row = @mysql_fetch_array($result, MYSQL_BOTH) ) { $x3 = '<a href="'.$producturl.$row['url'].'" style="color:#0000FF;"><img src="'.$imageurl.$row['img'].'" border="none" alt="'.$row['title'].'" /><br />'.$row['title'].'</a>'; $x3a = '£'.$row['price']; $x3b = '<form method="post" action="https://www.domain.co.uk/s_quickadd.php" target="_blank"><input type="hidden" name="code" value="'.$row['code'].'" /><input type="image" src="images/add.gif" name="Submit" alt="Add To Cart" /></form>'; } $sql = "SELECT code, title, img, url, price FROM products WHERE active='1' AND live='1' AND productid='".$x4."'"; $result = mysql_query($sql); while ( $row = @mysql_fetch_array($result, MYSQL_BOTH) ) { $x4 = '<a href="'.$producturl.$row['url'].'" style="color:#0000FF;"><img src="'.$imageurl.$row['img'].'" border="none" alt="'.$row['title'].'" /><br />'.$row['title'].'</a>'; $x4a = '£'.$row['price']; $x4b = '<form method="post" action="https://www.domain.co.uk/s_quickadd.php" target="_blank"><input type="hidden" name="code" value="'.$row['code'].'" /><input type="image" src="images/add.gif" name="Submit" alt="Add To Cart" /></form>'; } } $data .= ' <table border="0" width="600px"> <tr style="background-color: #999999; color:#FFFFFF; font-weight: bold; font-size: 12px; font-family:Verdana, Arial, Helvetica, sans-serif;"> <td colspan="4">You may also be interested in....</td> </tr> <tr> <td align="center" style="vertical-align:top; font-size: 12px; font-family:Verdana, Arial, Helvetica, sans-serif;">'.$x1.'</td> <td align="center" style="vertical-align:top; font-size: 12px; font-family:Verdana, Arial, Helvetica, sans-serif;">'.$x2.'</td> <td align="center" style="vertical-align:top; font-size: 12px; font-family:Verdana, Arial, Helvetica, sans-serif;">'.$x3.'</td> <td align="center" style="vertical-align:top; font-size: 12px; font-family:Verdana, Arial, Helvetica, sans-serif;">'.$x4.'</td> </tr> <tr> <td align="center" style="font-size: 12px; font-family:Verdana, Arial, Helvetica, sans-serif;">'.$x1a.'</td> <td align="center" style="font-size: 12px; font-family:Verdana, Arial, Helvetica, sans-serif;">'.$x2a.'</td> <td align="center" style="font-size: 12px; font-family:Verdana, Arial, Helvetica, sans-serif;">'.$x3a.'</td> <td align="center" style="font-size: 12px; font-family:Verdana, Arial, Helvetica, sans-serif;">'.$x4a.'</td> </tr> <tr> <td align="center" style="font-size: 12px; font-family:Verdana, Arial, Helvetica, sans-serif;">'.$x1b.'</td> <td align="center" style="font-size: 12px; font-family:Verdana, Arial, Helvetica, sans-serif;">'.$x2b.'</td> <td align="center" style="font-size: 12px; font-family:Verdana, Arial, Helvetica, sans-serif;">'.$x3b.'</td> <td align="center" style="font-size: 12px; font-family:Verdana, Arial, Helvetica, sans-serif;">'.$x4b.'</td> </tr> </table> '; break; } } I was trying to merge that case with this one :- case 19: //Displays the cart summary with icons. The id of the cart comes from the session variables $sql = "SELECT cartid FROM carts WHERE progress='0' AND ipaddress='".mysql_real_escape_string($_SERVER['REMOTE_ADDR'])."' AND browser='".mysql_real_escape_string($_SERVER['HTTP_USER_AGENT'])."' AND datestarted >= '".mysql_real_escape_string(date("Y-m-d H:i:s", mktime(date("H"),(date("i")-$timedelay),date("s"),date("m"),date("d"),date("Y"))))."' ORDER BY cartid DESC LIMIT 1"; $result = mysql_query($sql); if ( mysql_num_rows($result) != 0 ) { $row = mysql_fetch_row($result); $_SESSION['cartid'] = $row[0]; } $data = '<font size="2" face="Verdana, Arial, Helvetica, sans-serif"color="#000000">'; if ( !(isset($_SESSION['cartid'])) || ($_SESSION['cartid'] == "") ) //if ( (!isset($_COOKIE['RITD_Cart_ID'])) || ($_COOKIE['RITD_Cart_ID'] == '') ) { $data .= '<img src="images/cart.jpg" alt="Cart is empty" width="27" height="15" hspace="2">'; $data .= 'No items have been added to the cart yet.'; } else { $sql = "SELECT sub FROM carts WHERE cartid='".$_SESSION['cartid']."'"; //$sql = "SELECT orderno, sub FROM carts WHERE cartid='".$_COOKIE['RITD_Cart_ID']."'"; $result = mysql_query($sql); while ( $row = @mysql_fetch_array($result, MYSQL_BOTH) ) { if ( $row['sub'] == "" ) { $row['sub'] = "0.00"; } $orderno = $orderpre . ($orderstart+$_SESSION['cartid']); $data .= '<img src="images/cart.jpg" alt="Items in cart" width="27" height="15" hspace="2">'; $data .= 'Order Number: '.$orderno.' with Sub-Total: £'.$row['sub']; $data = str_replace("&", "&", $data); } } $data .= '</font>'; break; Which resulted in me making a new case 21 which was this :- case 21: //Displays the add to cart form & cross selling info. Requires product ID $sql = "SELECT code FROM products WHERE productid='".mysql_real_escape_string($_GET['id'])."'"; $result = mysql_query($sql); while ( $row = @mysql_fetch_array($result, MYSQL_BOTH) ) { $data = '<font size="2" face="Verdana, Arial, Helvetica, sans-serif"color="#000000"><form method="post" action="https://www.domain.co.uk/s_addtocart.php" target="_blank"><input type="hidden" name="code" value="'.$row['code'].'" /><input type="image" src="images/add.gif" name="Submit" alt="Add To Cart" style="vertical-align:middle; border: none;" />Quantity: <input type="text" name="quantity" size="3" value="1" /></form></font>'; } //Displays cross selling information. Requires product ID $xprods = array(); $sql = "SELECT xselling.xproductid FROM xselling, products WHERE xselling.xproductid=products.productid AND xselling.active='1' AND products.active='1' AND products.live='1' AND xselling.productid='".mysql_real_escape_string($_GET['id'])."'"; $result = mysql_query($sql); while ( $row = @mysql_fetch_array($result, MYSQL_BOTH) ) { array_push($xprods, $row['xproductid']); } if ( (count($xprods) <= 4) && (count($xprods) > 0) ) { $a = 0; $b = count($xprods); while ( $a < $b ) { $sql = "SELECT code, title, img, url, price FROM products WHERE active='1' AND live='1' AND productid='".$xprods[$a]."'"; $result = mysql_query($sql); switch ($a) { case 0: $row = mysql_fetch_assoc($result); $x1 = '<a href="'.$producturl.$row['url'].'" style="color:#0000FF;"><img src="'.$imageurl.$row['img'].'" border="none" alt="'.$row['title'].'" /><br />'.$row['title'].'</a>'; $x1a = '£'.$row['price']; $x1b = '<form method="post" action="https://www.domain.co.uk/s_quickadd.php" target="_blank"><input type="hidden" name="code" value="'.$row['code'].'" /><input type="image" src="images/add.gif" name="Submit" alt="Add To Cart" /></form>'; break; case 1: $row = mysql_fetch_assoc($result); $x2 = '<a href="'.$producturl.$row['url'].'" style="color:#0000FF;"><img src="'.$imageurl.$row['img'].'" border="none" alt="'.$row['title'].'" /><br />'.$row['title'].'</a>'; $x2a = '£'.$row['price']; $x2b = '<form method="post" action="https://www.domain.co.uk/s_quickadd.php" target="_blank"><input type="hidden" name="code" value="'.$row['code'].'" /><input type="image" src="images/add.gif" name="Submit" alt="Add To Cart" /></form>'; break; case 2: $row = mysql_fetch_assoc($result); $x3 = '<a href="'.$producturl.$row['url'].'" style="color:#0000FF;"><img src="'.$imageurl.$row['img'].'" border="none" alt="'.$row['title'].'" /><br />'.$row['title'].'</a>'; $x3a = '£'.$row['price']; $x3b = '<form method="post" action="https://www.domain.co.uk/s_quickadd.php" target="_blank"><input type="hidden" name="code" value="'.$row['code'].'" /><input type="image" src="images/add.gif" name="Submit" alt="Add To Cart" /></form>'; break; case 3: $row = mysql_fetch_assoc($result); $x4 = '<a href="'.$producturl.$row['url'].'" style="color:#0000FF;"><img src="'.$imageurl.$row['img'].'" border="none" alt="'.$row['title'].'" /><br />'.$row['title'].'</a>'; $x4a = '£'.$row['price']; $x4b = '<form method="post" action="https://www.domain.co.uk/s_quickadd.php" target="_blank"><input type="hidden" name="code" value="'.$row['code'].'" /><input type="image" src="images/add.gif" name="Submit" alt="Add To Cart" /></form>'; break; } $a++; } } elseif ( count($xprods) > 4 ) { $c = 0; while ( $c < 4 ) { $pick = rand(1,count($xprods)); $pick = $pick - 1; switch ($c) { case 0: $x1 = $xprods[$pick]; break; case 1: $x2 = $xprods[$pick]; break; case 2: $x3 = $xprods[$pick]; break; case 3: $x4 = $xprods[$pick]; break; } unset($xprods[$pick]); $xprods = array_values($xprods); $c++; } $sql = "SELECT code, title, img, url, price FROM products WHERE active='1' AND live='1' AND productid='".$x1."'"; $result = mysql_query($sql); while ( $row = @mysql_fetch_array($result, MYSQL_BOTH) ) { $x1 = '<a href="'.$producturl.$row['url'].'" style="color:#0000FF;"><img src="'.$imageurl.$row['img'].'" border="none" alt="'.$row['title'].'" /><br />'.$row['title'].'</a>'; $x1a = '£'.$row['price']; $x1b = '<form method="post" action="https://www.domain.co.uk/s_quickadd.php" target="_blank"><input type="hidden" name="code" value="'.$row['code'].'" /><input type="image" src="images/add.gif" name="Submit" alt="Add To Cart" /></form>'; } $sql = "SELECT code, title, img, url, price FROM products WHERE active='1' AND live='1' AND productid='".$x2."'"; $result = mysql_query($sql); while ( $row = @mysql_fetch_array($result, MYSQL_BOTH) ) { $x2 = '<a href="'.$producturl.$row['url'].'" style="color:#0000FF;"><img src="'.$imageurl.$row['img'].'" border="none" alt="'.$row['title'].'" /><br />'.$row['title'].'</a>'; $x2a = '£'.$row['price']; $x2b = '<form method="post" action="https://www.domain.co.uk/s_quickadd.php" target="_blank"><input type="hidden" name="code" value="'.$row['code'].'" /><input type="image" src="images/add.gif" name="Submit" alt="Add To Cart" /></form>'; } $sql = "SELECT code, title, img, url, price FROM products WHERE active='1' AND live='1' AND productid='".$x3."'"; $result = mysql_query($sql); while ( $row = @mysql_fetch_array($result, MYSQL_BOTH) ) { $x3 = '<a href="'.$producturl.$row['url'].'" style="color:#0000FF;"><img src="'.$imageurl.$row['img'].'" border="none" alt="'.$row['title'].'" /><br />'.$row['title'].'</a>'; $x3a = '£'.$row['price']; $x3b = '<form method="post" action="https://www.domain.co.uk/s_quickadd.php" target="_blank"><input type="hidden" name="code" value="'.$row['code'].'" /><input type="image" src="images/add.gif" name="Submit" alt="Add To Cart" /></form>'; } $sql = "SELECT code, title, img, url, price FROM products WHERE active='1' AND live='1' AND productid='".$x4."'"; $result = mysql_query($sql); while ( $row = @mysql_fetch_array($result, MYSQL_BOTH) ) { $x4 = '<a href="'.$producturl.$row['url'].'" style="color:#0000FF;"><img src="'.$imageurl.$row['img'].'" border="none" alt="'.$row['title'].'" /><br />'.$row['title'].'</a>'; $x4a = '£'.$row['price']; $x4b = '<form method="post" action="https://www.domain.co.uk/s_quickadd.php" target="_blank"><input type="hidden" name="code" value="'.$row['code'].'" /><input type="image" src="images/add.gif" name="Submit" alt="Add To Cart" /></form>'; } } $data .= ' <table border="0" width="600px"> <tr style="background-color: #999999; color:#FFFFFF; font-weight: bold; font-size: 12px; font-family:Verdana, Arial, Helvetica, sans-serif;"> <td colspan="4">You may also be interested in....</td> </tr> <tr> <td align="center" style="vertical-align:top; font-size: 12px; font-family:Verdana, Arial, Helvetica, sans-serif;">'.$x1.'</td> <td align="center" style="vertical-align:top; font-size: 12px; font-family:Verdana, Arial, Helvetica, sans-serif;">'.$x2.'</td> <td align="center" style="vertical-align:top; font-size: 12px; font-family:Verdana, Arial, Helvetica, sans-serif;">'.$x3.'</td> <td align="center" style="vertical-align:top; font-size: 12px; font-family:Verdana, Arial, Helvetica, sans-serif;">'.$x4.'</td> </tr> <tr> <td align="center" style="font-size: 12px; font-family:Verdana, Arial, Helvetica, sans-serif;">'.$x1a.'</td> <td align="center" style="font-size: 12px; font-family:Verdana, Arial, Helvetica, sans-serif;">'.$x2a.'</td> <td align="center" style="font-size: 12px; font-family:Verdana, Arial, Helvetica, sans-serif;">'.$x3a.'</td> <td align="center" style="font-size: 12px; font-family:Verdana, Arial, Helvetica, sans-serif;">'.$x4a.'</td> </tr> <tr> <td align="center" style="font-size: 12px; font-family:Verdana, Arial, Helvetica, sans-serif;">'.$x1b.'</td> <td align="center" style="font-size: 12px; font-family:Verdana, Arial, Helvetica, sans-serif;">'.$x2b.'</td> <td align="center" style="font-size: 12px; font-family:Verdana, Arial, Helvetica, sans-serif;">'.$x3b.'</td> <td align="center" style="font-size: 12px; font-family:Verdana, Arial, Helvetica, sans-serif;">'.$x4b.'</td> </tr> </table> '; //Displays the cart summary with icons. The id of the cart comes from the session variables $sql = "SELECT cartid FROM carts WHERE progress='0' AND ipaddress='".mysql_real_escape_string($_SERVER['REMOTE_ADDR'])."' AND browser='".mysql_real_escape_string($_SERVER['HTTP_USER_AGENT'])."' AND datestarted >= '".mysql_real_escape_string(date("Y-m-d H:i:s", mktime(date("H"),(date("i")-$timedelay),date("s"),date("m"),date("d"),date("Y"))))."' ORDER BY cartid DESC LIMIT 1"; $result = mysql_query($sql); if ( mysql_num_rows($result) != 0 ) { $row = mysql_fetch_row($result); $_SESSION['cartid'] = $row[0]; } $data = '<font size="2" face="Verdana, Arial, Helvetica, sans-serif"color="#000000">'; if ( !(isset($_SESSION['cartid'])) || ($_SESSION['cartid'] == "") ) //if ( (!isset($_COOKIE['RITD_Cart_ID'])) || ($_COOKIE['RITD_Cart_ID'] == '') ) { $data .= '<img src="images/cart.jpg" alt="Cart is empty" width="27" height="15" hspace="2">'; $data .= 'No items have been added to the cart yet.'; } else { $sql = "SELECT sub FROM carts WHERE cartid='".$_SESSION['cartid']."'"; //$sql = "SELECT orderno, sub FROM carts WHERE cartid='".$_COOKIE['RITD_Cart_ID']."'"; $result = mysql_query($sql); while ( $row = @mysql_fetch_array($result, MYSQL_BOTH) ) { if ( $row['sub'] == "" ) { $row['sub'] = "0.00"; } $orderno = $orderpre . ($orderstart+$_SESSION['cartid']); $data .= '<img src="images/cart.jpg" alt="Items in cart" width="27" height="15" hspace="2">'; $data .= 'Order Number: '.$orderno.' with Sub-Total: £'.$row['sub']; $data = str_replace("&", "&", $data); } } $data .= '</font>'; break; } } But all that displays on the webpage is the info from the original case 19. Any ideas? Thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.