My own shoping cart
Hi could someone help me with this shopping cart.
I have taken this from a tutorial on web. Everything works fine except the remove item function
Can someone help with remove_item function
<?php
include("db.php");
switch($_GET["action"])
{
case "add_item":
{
AddItem($_GET["ID"], $_GET["VarID"], $_GET["MetVar"], $_GET["Pintyp"], $_GET["Pinvar"], $_GET["qty"]);
ShowCart();
break;
}
case "update_item":
{
UpdateItem($_GET["ID"], $_GET["VarID"], $_GET["MetVar"], $_GET["Pintyp"], $_GET["Pinvar"], $_GET["qty"]);
ShowCart();
break;
}
case "remove_item":
{
RemoveItem($_GET["ID"], $_GET["VarID"], $_GET["MetVar"], $_GET["Pintyp"], $_GET["Pinvar"]);
ShowCart();
break;
}
default:
{
ShowCart();
}
}
function AddItem ($PID, $VID, $METID, $PTID, $PVID, $qty)
{
global $dbServer, $dbUser, $dbPass, $dbName;
// Get a connection to the database
$cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName);
$result = mysql_query("select count(*) from cart where cookieId = '" . GetCartId() . "' and PID = $PID and VID = $VID and METID = $METID and PTID = $PTID and PVID = $PVID");
$row = mysql_fetch_row($result);
$numRows = $row[0];
if($numRows == 0)
{
// This item doesn't exist in the users cart,
// we will add it with an insert query
@mysql_query("insert into cart(cookieId, PID, VID, METID, PTID, PVID, qty) values('" . GetCartId() . "', $PID, $VID, $METID, $PTID, $PVID, $qty)");
}
else
{
// This item already exists in the users cart,
// we will update it instead
UpdateItem($PID, $VID, $METID, $PTID, $PVID, $qty);
}
}
function UpdateItem($PID, $VID, $METID, $PTID, $PVID, $qty)
{
global $dbServer, $dbUser, $dbPass, $dbName;
// Get a connection to the database
$cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName);
if($qty == 0)
{
// Remove the item from the users cart
RemoveItem($PID, $VID, $METID, $PTID, $PVID);
}
else
{
mysql_query("update cart set qty = $qty where cookieId = '" . GetCartId() . "' and PID = $PID and VID = $VID and METID = $METID and PTID = $PTID and PVID = $PVID");
}
}
function RemoveItem($PID, $VID, $METID, $PTID, $PVID)
{
// Uses an SQL delete statement to remove an item from
// the users cart
global $dbServer, $dbUser, $dbPass, $dbName;
// Get a connection to the database
$cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName);
mysql_query("delete from cart where cookieId = '" . GetCartId() . "' and PID = $PID and VID = $VID and METID = $METID and PTID = $PTID and PVID = $PVID");
}
function ShowCart()
{
// Gets each item from the cart table and display them in
// a tabulated format, as well as a final total for the cart
global $dbServer, $dbUser, $dbPass, $dbName;
// Get a connection to the database
$cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName);
$totalCost = 0;
$result = mysql_query("SELECT cart.*, product.Name, product.Price, product.Descirpt, varit.Varit as PV, metallivarit.varit as MV, pinnityp.tyyppi, pinninvari.vari as PNV FROM pinninvari INNER JOIN (pinnityp INNER JOIN (metallivarit INNER JOIN (varit INNER JOIN (cart INNER JOIN product ON cart.PID = product.PID) ON varit.ID = cart.VID) ON metallivarit.ID = cart.METID) ON pinnityp.ID = cart.PTID) ON pinninvari.id = cart.PVID
where cart.cookieId = '" . GetCartId() . "' order by product.Name asc");
?>
<!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>Untitled Document</title>
<link href="../Styles/aaria.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="frmCart" name="frmCart" method="get" action="">
<table width="640" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
<tr>
<td width="8" class="style5"> </td>
<td width="46" class="style5"><strong>Nimi</strong></td>
<td width="110" class="style5"><strong>Tuotetieto</strong></td>
<td width="37" class="style5"><strong>Väri</strong></td>
<td width="104" class="style5"><strong>Metallinväri</strong></td>
<td width="95" class="style5"><strong>Pinnityyppi</strong></td>
<td width="85" class="style5"><strong>Pinninväri</strong></td>
<td width="40" class="style5"><strong>Kpl</strong></td>
<td width="66" class="style5"><strong>Hinta</strong></td>
<td width="49" class="style5"><strong>Poista</strong></td>
</tr>
<?php
while($row = mysql_fetch_array($result))
{
// Increment the total cost of all items
$totalCost += ($row["qty"] * $row["Price"]);
?>
<tr>
<td class="style5"> </td>
<td valign="top" class="style5"><?php echo $row["Name"]; ?> </td>
<td width="110" valign="top" class="style5"><?php echo $row["Descirpt"]; ?></td>
<td valign="top" class="style5"><?php echo $row["PV"]; ?> </td>
<td valign="top" class="style5"><?php echo $row["MV"]; ?> </td>
<td valign="top" class="style5"><?php echo $row["tyyppi"]; ?> </td>
<td valign="top" class="style5"><?php echo $row["PNV"]; ?> </td>
<td valign="top" class="style5"><?php echo $row["qty"]; ?> </td>
<td valign="top" class="style5"><?php echo number_format($row["Price"], 2, ".", ",");; ?> #8364;</td>
<td valign="top" class="style5"><a href="cart.php?action=remove_item&id=<?php echo $row["PID"];?>&VarID=<?php echo $row["VID"];?>&MetVar=<?php echo $row["METID"];?>&Pintyp=<?php echo $row["PTID"];?>&Pinvar=<?php echo $row["PVID"];?>">Poista</a> </td>
</tr>
<?php
}
?>
<tr>
<td class="style5"> </td>
<td class="style5"> </td>
<td class="style5"> </td>
<td class="style5"> </td>
<td class="style5"> </td>
<td class="style5"> </td>
<td class="style5"> </td>
<td class="style5"> </td>
<td class="style5"> </td>
<td class="style5"> </td>
</tr>
<tr>
<td class="style5"> </td>
<td class="style5"> </td>
<td class="style5"> </td>
<td class="style5"> </td>
<td class="style5"> </td>
<td class="style5"> </td>
<td class="style5"> </td>
<td class="style5"><div align="right"><strong>Total:</strong></div></td>
<td class="style5"><strong><?php echo number_format($totalCost, 2, ".", ","); ?> #8364;</strong></td>
<td class="style5"> </td>
</tr>
<tr>
<td class="style5"> </td>
<td class="style5"> </td>
<td class="style5"> </td>
<td class="style5"> </td>
<td class="style5"> </td>
<td class="style5"> </td>
<td class="style5"> </td>
<td class="style5"> </td>
<td class="style5"> </td>
<td class="style5"> </td>
</tr>
</table>
<?php
}
?>
</form>
</body>
</html>
thx
|