siyah miyah
Apr 28th 2008, 7:07 am
This is my cart.php file with the error:
Notice: Undefined index: prod_id in /**********************/*****/****/*******/******/******/web/fsbasket/cart.php on line 20
prod_id is the reference to the column in my database....so in my query I am calling on the prod_id for the shopping basket....Can someone tell me why I get this msg?
Is there a problem with connecting to the database perhaps?
<?php
// Include MySQL class
include("mysql.class.php");
// Include database connection
include("global.inc");
// Include functions
include("functions.inc");
// Start the session
session_start();
// Process actions
$cart = $_SESSION['cart'];
$action = $_GET['action'];
switch ($action) {
case 'add':
if ($cart) {
$cart .= ','.$_GET['prod_id'];
} else {
$cart = $_GET['prod_id'];
}
break;
case 'delete':
if ($cart) {
$items = explode(',',$cart);
$newcart = '';
foreach ($items as $item) {
if ($_GET['prod_id'] != $item) {
if ($newcart != '') {
$newcart .= ','.$item;
} else {
$newcart = $item;
}
}
}
$cart = $newcart;
}
break;
case 'update':
if ($cart) {
$newcart = '';
foreach ($_POST as $key=>$value) {
if (stristr($key,'qty')) {
$prod_id = str_replace('qty','',$key);
$items = ($newcart != '') ? explode(',',$newcart) : explode(',',$cart);
$newcart = '';
foreach ($items as $item) {
if ($prod_id != $item) {
if ($newcart != '') {
$newcart .= ','.$item;
} else {
$newcart = $item;
}
}
}
for ($i=1;$i<=$value;$i++) {
if ($newcart != '') {
$newcart .= ','.$prod_id;
} else {
$newcart = $prod_id;
}
}
}
}
}
$cart = $newcart;
break;
}
$_SESSION['cart'] = $cart;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Shopping Basket</title>
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<div id="shoppingcart">
<h1>Your Shopping Basket</h1>
<?php
echo writeShoppingCart();
?>
</div>
<div id="contents">
<h1>Please check quantities</h1>
<?php
echo showCart();
?>
<p><a href="index.php">Return to homepage</a></p>
</div>
</body>
</html>
Thanks, in advance, for any responses!
Notice: Undefined index: prod_id in /**********************/*****/****/*******/******/******/web/fsbasket/cart.php on line 20
prod_id is the reference to the column in my database....so in my query I am calling on the prod_id for the shopping basket....Can someone tell me why I get this msg?
Is there a problem with connecting to the database perhaps?
<?php
// Include MySQL class
include("mysql.class.php");
// Include database connection
include("global.inc");
// Include functions
include("functions.inc");
// Start the session
session_start();
// Process actions
$cart = $_SESSION['cart'];
$action = $_GET['action'];
switch ($action) {
case 'add':
if ($cart) {
$cart .= ','.$_GET['prod_id'];
} else {
$cart = $_GET['prod_id'];
}
break;
case 'delete':
if ($cart) {
$items = explode(',',$cart);
$newcart = '';
foreach ($items as $item) {
if ($_GET['prod_id'] != $item) {
if ($newcart != '') {
$newcart .= ','.$item;
} else {
$newcart = $item;
}
}
}
$cart = $newcart;
}
break;
case 'update':
if ($cart) {
$newcart = '';
foreach ($_POST as $key=>$value) {
if (stristr($key,'qty')) {
$prod_id = str_replace('qty','',$key);
$items = ($newcart != '') ? explode(',',$newcart) : explode(',',$cart);
$newcart = '';
foreach ($items as $item) {
if ($prod_id != $item) {
if ($newcart != '') {
$newcart .= ','.$item;
} else {
$newcart = $item;
}
}
}
for ($i=1;$i<=$value;$i++) {
if ($newcart != '') {
$newcart .= ','.$prod_id;
} else {
$newcart = $prod_id;
}
}
}
}
}
$cart = $newcart;
break;
}
$_SESSION['cart'] = $cart;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Shopping Basket</title>
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<div id="shoppingcart">
<h1>Your Shopping Basket</h1>
<?php
echo writeShoppingCart();
?>
</div>
<div id="contents">
<h1>Please check quantities</h1>
<?php
echo showCart();
?>
<p><a href="index.php">Return to homepage</a></p>
</div>
</body>
</html>
Thanks, in advance, for any responses!