Hi
i am having problems with some code that i wrote out for a shopping cart. the shopping cart it self works when a product is added but when the 'CART CONTENT' button is clicked on it comes up with an error. the error is
Notice: Undefined index: action in D:\www\students \khank\WebsiteF inal1SHAZAD\car t.php on line 5
the code that i have written for this is
[code=php]
<?php
include("databa se.php");
switch($_GET["action"])
{
case "add_item":
{
AddItem($_GET["id"], $_GET["qty"]);
ShowCart();
break;
}
case "update_ite m":
{
UpdateItem($_GE T["id"], $_GET["qty"]);
ShowCart();
break;
}
case "remove_ite m":
{
RemoveItem($_GE T["id"]);
ShowCart();
break;
}
case "default":
{
ShowCart();
}
}
function AddItem($produc tid, $qty)
{
// Will check whether or not this item
// already exists in the cart table.
// If it does, the UpdateItem function
// will be called instead
global $host, $user, $pass;
// Get a connection to the database
$cxn = @mysql_connect( "$host", "$user", "$pass");
$result = mysql_query("se lect count(*) from cart where cookieid = '" . GetCartId() . "'");
$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("i nsert into cart(cookieid,p roductid,qty) values('" . GetCartId() . "',$productid,$ qty)") or die(mysql_error ());
}
else
{
// This item already exists in the users cart,
// we will update it instead
UpdateItem($pro ductid, $qty);
}
}
function UpdateItem($pro ductid, $qty)
{
// Updates the quantity of an item in the users cart.
// If the qutnaity is zero, then RemoveItem will be
// called instead
global $host, $user, $pass;
// Get a connection to the database
$cxn = @mysql_connect( "$host", "$user", "$pass");
if($qty == 0)
{
// Remove the item from the users cart
RemoveItem($pro ductid);
}
else
{
mysql_query("up date cart set qty = $qty where cookieid = '" . GetCartId() . "' and productid = $productid");
}
}
function RemoveItem($pro ductid)
{
// Uses an SQL delete statement to remove an item from
// the users cart
global $host, $user, $pass;
// Get a connection to the database
$cxn = @mysql_connect( "$host", "$user", "$pass");
mysql_query("de lete from cart where cookieid = '" . GetCartId() . "' and productid = $productid");
}
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 $host, $user, $pass;
// Get a connection to the database
$cxn = @mysql_connect( "$host", "$user", "$pass");
$totalCost = 0;
$result = mysql_query("se lect * from cart c join products p on c.productid = p.productid where c.cookieid = '" . GetCartId() . "'");
//$result = mysql_query("se lect * from cart c inner join products p on c.productid = p.productid");
?>
[/code]
the error comes on line five with the 'SWITCH STATEMENT'. i don't know what to do. Can any one please help. it would be very much appreciated.
i am having problems with some code that i wrote out for a shopping cart. the shopping cart it self works when a product is added but when the 'CART CONTENT' button is clicked on it comes up with an error. the error is
Notice: Undefined index: action in D:\www\students \khank\WebsiteF inal1SHAZAD\car t.php on line 5
the code that i have written for this is
[code=php]
<?php
include("databa se.php");
switch($_GET["action"])
{
case "add_item":
{
AddItem($_GET["id"], $_GET["qty"]);
ShowCart();
break;
}
case "update_ite m":
{
UpdateItem($_GE T["id"], $_GET["qty"]);
ShowCart();
break;
}
case "remove_ite m":
{
RemoveItem($_GE T["id"]);
ShowCart();
break;
}
case "default":
{
ShowCart();
}
}
function AddItem($produc tid, $qty)
{
// Will check whether or not this item
// already exists in the cart table.
// If it does, the UpdateItem function
// will be called instead
global $host, $user, $pass;
// Get a connection to the database
$cxn = @mysql_connect( "$host", "$user", "$pass");
$result = mysql_query("se lect count(*) from cart where cookieid = '" . GetCartId() . "'");
$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("i nsert into cart(cookieid,p roductid,qty) values('" . GetCartId() . "',$productid,$ qty)") or die(mysql_error ());
}
else
{
// This item already exists in the users cart,
// we will update it instead
UpdateItem($pro ductid, $qty);
}
}
function UpdateItem($pro ductid, $qty)
{
// Updates the quantity of an item in the users cart.
// If the qutnaity is zero, then RemoveItem will be
// called instead
global $host, $user, $pass;
// Get a connection to the database
$cxn = @mysql_connect( "$host", "$user", "$pass");
if($qty == 0)
{
// Remove the item from the users cart
RemoveItem($pro ductid);
}
else
{
mysql_query("up date cart set qty = $qty where cookieid = '" . GetCartId() . "' and productid = $productid");
}
}
function RemoveItem($pro ductid)
{
// Uses an SQL delete statement to remove an item from
// the users cart
global $host, $user, $pass;
// Get a connection to the database
$cxn = @mysql_connect( "$host", "$user", "$pass");
mysql_query("de lete from cart where cookieid = '" . GetCartId() . "' and productid = $productid");
}
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 $host, $user, $pass;
// Get a connection to the database
$cxn = @mysql_connect( "$host", "$user", "$pass");
$totalCost = 0;
$result = mysql_query("se lect * from cart c join products p on c.productid = p.productid where c.cookieid = '" . GetCartId() . "'");
//$result = mysql_query("se lect * from cart c inner join products p on c.productid = p.productid");
?>
[/code]
the error comes on line five with the 'SWITCH STATEMENT'. i don't know what to do. Can any one please help. it would be very much appreciated.
Comment