Hi,
I have the following shopping cart that works perfectly on my home PC.
What happens when I try to run the script online is:Code:<?php // start session session_start(); ?> <!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"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>my title</title> <link href="css/style.css" rel="stylesheet" type="text/css" /> </head> <body> <center> <table align="center" class="maintable"> <tr> <td colspan="2"> <!--Top Block Starts --> <?php include('inctop.php'); ?> <!--Top Block Ends --> </td> </tr> <!--Left Block Starts --> <tr> <td class="blk2_lp" width="30%" valign="top"> <?php include('inccategories.php'); ?> </td> <!--Left Block Ends --> <!--Right Block Starts --> <td valign="top"> <span class="wel">Your Shopping Cart</span><br><br> <?php include('[path to connection file].php'); if ($_GET['itemtoadd']) { $itemtoadd = $_GET['itemtoadd']; $_SESSION['shoppingcart'][$itemtoadd] = 1; } if ($_GET['itemtoremove']) { $itemtoremove = $_GET['itemtoremove']; unset($_SESSION['shoppingcart'][$itemtoremove]); } if (isset($_POST['cmdupdatecart'])) { foreach ($_POST['user_qty'] as $cartitem => $newqty) { if ( $newqty== 0 ) { unset ($_SESSION['shoppingcart'][$cartitem]); } elseif ( $newqty > 0 ) { $_SESSION['shoppingcart'][$cartitem] = $newqty; } next($_POST['user_qty']); } } $mycart = $_SESSION['shoppingcart']; echo "<form action ='shoppingcart.php' method ='post'>"; echo "<table ALIGN=\"center\" WIDTH=\"90%\" class=\"noborders\">"; if (is_array($mycart)) { echo "<TR class=\"header\">"; echo "<TD width = \"5%\"> </td>"; echo "<TD width = \"20%\"> </td>"; echo "<TD width = \"35%\"><B>Item</B></font> </td>"; echo "<TD width = \"10%\">Unit Price</td>"; echo "<TD width = \"10%\">Quantity</td>"; echo "<TD width = \"10%\">Total Price</td>"; echo "<TD width = \"10%\">Remove</td>"; echo "</TR>"; $dbconnection = mysql_connect($dbhost,$dbusername,$dbpassword); mysql_select_db($database,$dbconnection ); $counter = 1; $totalprice = 0; foreach ($mycart as $itemqty) { $cartitemid = key($mycart); $sql = "SELECT * FROM tblitems WHERE itemid = $cartitemid"; $result = mysql_query($sql,$dbconnection) or die(mysql_error()); $myrow = mysql_fetch_array($result); $itemid = $myrow['itemid']; $itemname = $myrow["itemname"]; $itemprice = $myrow["itemprice"]; $itemtotalprice = $itemprice * $itemqty; $itempicturename = (empty($myrow["itempicture"])) ? 'default.jpg' : $myrow["itempicture"]; $itempicture = "<img src=\"demo/itempics/$itempicturename\" width=\"100\" height=\"100\">"; $mysubcategoryidf = $myrow["subcategoryidf"]; $subcategoryname = getsubcategoryname($mysubcategoryidf); if($counter % 2) { echo "<TR>"; } else { echo "<TR bgcolor=\"#CCCCCC\">\n"; }//colour has now been set :-) echo "<TD>$counter</td>"; echo "<TD>$itempicture</td>"; echo "<TD>$itemname</td>"; echo "<TD align='right'>".number_format($itemprice,2)."</td>"; echo "<TD align='right'><input size='4' type='text' name=\"user_qty[".$itemid."]\" value='$itemqty'></td>"; //echo "<TD>$itemqty</td>"; echo "<TD align='right'>".number_format($itemtotalprice,2)."</td>"; echo "<TD><a href=\"shoppingcart.php?itemtoremove=$itemid\">Remove</a></td>"; echo "</tr>"; $counter = $counter + 1; $totalprice = $totalprice + $itemtotalprice; next($mycart); } echo "<tr class=\"header\">"; echo "<td colspan='5' align='right'>Your Total Price is:</td>"; echo "<td align='right'><b>".number_format($totalprice,2)."</b></td>"; echo "<td> </td>"; echo "</tr>"; echo "<tr>"; echo "<td colspan='5' align='right'>Update Cart</td>"; echo "<td align='right'><input name=\"cmdupdatecart\" value=\"Update\" type=\"submit\"></td>"; echo "<td> </td>"; echo "</tr>"; echo "<tr>"; echo "<td colspan='5' align='right'>--</td>"; echo "<td align='right'><a href='shoppingcheckout.php'>Checkout</a></td>"; echo "<td> </td>"; echo "</tr>"; } else { echo "<tr><td>Your Shopping cart is currently empty</td><tr>"; } echo "</table>"; echo "</form>"; function getsubcategoryname($subcategoryidf){ $subcategoryresult = mysql_query("SELECT * FROM tblsubcategories WHERE subcategoryid = $subcategoryidf"); $mysubcategory = mysql_fetch_array($subcategoryresult); $subcategoryname = $mysubcategory['subcategoryname']; return $subcategoryname; } ?> </td> <!--Right Block Ends --> <!--Content Block Ends --> </tr> <tr> <td colspan="2"> <div id="sub_block2"> <?php include('incbott.php'); ?> </div> </td> </tr> </table> </center> </body> </html>
1) I successfully add the first itrm to the Cart and the shopping cart displays
2) When I add additional items, I get an error saying:
The error appears above the Shopping cartYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
3) All the other items in the cart display except the first one
4) The Update and Checkout links do NOT display
What am I missing?






Bookmarks