Ayuda..con mi carrito de compras.please...=(
Hola "davidcortesb" Primero,deseo agradecerte que me dediques un poco de tu valioso tiempo. Espero que me puedas ayudar o aunque sea dar una idea de como solucionar este problemita:
me sale este error en mi carrito de compras
Notice: Undefined index: cart in C:\wamp\www\cart-demo\cart-demo\inc\functions.inc.php on line 3
You have no items in your shopping cart
estos 3 estan en la carpeta inc
este es la pagina functions.inc.php
<?php
function writeShoppingCart() {
$cart = $_SESSION['cart'];
if (!$cart) {
return '
<p>You have no items in your shopping cart</p>
';
} else {
// Parse the cart session variable
$items = explode(',',$cart);
$s = (count($items) > 1) ? 's':'';
return '
<p>You have <a href="cart.php">'.count($items).' item'.$s.' in your shopping cart</a></p>
';
}
}
function showCart() {
global $db;
$cart = $_SESSION['cart'];
if ($cart) {
$items = explode(',',$cart);
$contents = array();
foreach ($items as $item) {
$contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1;
}
$output[] = '<form action="cart.php?action=update" method="post" id="cart">';
$output[] = '
<table>
';
foreach ($contents as $id=>$qty) {
$sql = 'SELECT * FROM books WHERE id = '.$id;
$result = $db->query($sql);
$row = $result->fetch();
extract($row);
$output[] = '
<tr>
';
$output[] = '
<td><a href="cart.php?action=delete&id='.$id.'" class="r">Remove</a></td>
';
$output[] = '
<td>'.$title.' by '.$author.'</td>
';
$output[] = '
<td>£'.$price.'</td>
';
$output[] = '
<td><input type="text" name="qty'.$id.'" value="'.$qty.'" size="3" maxlength="3" /></td>
';
$output[] = '
<td>£'.($price * $qty).'</td>
';
$total += $price * $qty;
$output[] = '
</tr>
';
}
$output[] = '
</table>
';
$output[] = '
<p>Grand total: <strong>£'.$total.'</strong></p>
';
$output[] = '
<div><button type="submit">Update cart</button></div>
';
$output[] = '</form>';
} else {
$output[] = '
<p>You shopping cart is empty.</p>
';
}
return join('',$output);
}
?>
mysql.class.php
<?php
/**
* MySQL Database Connection Class
* @access public
* @package SPLIB
*/
class MySQL {
/**
* MySQL server hostname
* @access private
* @var string
*/
var $host;
/**
* MySQL username
* @access private
* @var string
*/
var $dbUser;
/**
* MySQL user's password
* @access private
* @var string
*/
var $dbPass;
/**
* Name of database to use
* @access private
* @var string
*/
var $dbName;
/**
* MySQL Resource link identifier stored here
* @access private
* @var string
*/
var $dbConn;
/**
* Stores error messages for connection errors
* @access private
* @var string
*/
var $connectError;
/**
* MySQL constructor
* @param string host (MySQL server hostname)
* @param string dbUser (MySQL User Name)
* @param string dbPass (MySQL User Password)
* @param string dbName (Database to select)
* @access public
*/
function MySQL ($host,$dbUser,$dbPass,$dbName) {
$this->host=$host;
$this->dbUser=$dbUser;
$this->dbPass=$dbPass;
$this->dbName=$dbName;
$this->connectToDb();
}
/**
* Establishes connection to MySQL and selects a database
* @return void
* @access private
*/
function connectToDb () {
// Make connection to MySQL server
if (!$this->dbConn = @mysql_connect($this->host,
$this->dbUser,
$this->dbPass)) {
trigger_error('Could not connect to server');
$this->connectError=true;
// Select database
} else if ( dbName,$this->dbConn">!@mysql_select_db($this->dbName,$this->dbConn) ) {
trigger_error('Could not select database');
$this->connectError=true;
}
}
/**
* Checks for MySQL errors
* @return boolean
* @access public
*/
function isError () {
if ( $this->connectError )
return true;
$error=mysql_error ($this->dbConn);
if ( empty ($error)...
me sale este error en mi carrito de compras
Notice: Undefined index: cart in C:\wamp\www\cart-demo\cart-demo\inc\functions.inc.php on line 3
You have no items in your shopping cart
estos 3 estan en la carpeta inc
este es la pagina functions.inc.php
<?php
function writeShoppingCart() {
$cart = $_SESSION['cart'];
if (!$cart) {
return '
<p>You have no items in your shopping cart</p>
';
} else {
// Parse the cart session variable
$items = explode(',',$cart);
$s = (count($items) > 1) ? 's':'';
return '
<p>You have <a href="cart.php">'.count($items).' item'.$s.' in your shopping cart</a></p>
';
}
}
function showCart() {
global $db;
$cart = $_SESSION['cart'];
if ($cart) {
$items = explode(',',$cart);
$contents = array();
foreach ($items as $item) {
$contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1;
}
$output[] = '<form action="cart.php?action=update" method="post" id="cart">';
$output[] = '
<table>
';
foreach ($contents as $id=>$qty) {
$sql = 'SELECT * FROM books WHERE id = '.$id;
$result = $db->query($sql);
$row = $result->fetch();
extract($row);
$output[] = '
<tr>
';
$output[] = '
<td><a href="cart.php?action=delete&id='.$id.'" class="r">Remove</a></td>
';
$output[] = '
<td>'.$title.' by '.$author.'</td>
';
$output[] = '
<td>£'.$price.'</td>
';
$output[] = '
<td><input type="text" name="qty'.$id.'" value="'.$qty.'" size="3" maxlength="3" /></td>
';
$output[] = '
<td>£'.($price * $qty).'</td>
';
$total += $price * $qty;
$output[] = '
</tr>
';
}
$output[] = '
</table>
';
$output[] = '
<p>Grand total: <strong>£'.$total.'</strong></p>
';
$output[] = '
<div><button type="submit">Update cart</button></div>
';
$output[] = '</form>';
} else {
$output[] = '
<p>You shopping cart is empty.</p>
';
}
return join('',$output);
}
?>
mysql.class.php
<?php
/**
* MySQL Database Connection Class
* @access public
* @package SPLIB
*/
class MySQL {
/**
* MySQL server hostname
* @access private
* @var string
*/
var $host;
/**
* MySQL username
* @access private
* @var string
*/
var $dbUser;
/**
* MySQL user's password
* @access private
* @var string
*/
var $dbPass;
/**
* Name of database to use
* @access private
* @var string
*/
var $dbName;
/**
* MySQL Resource link identifier stored here
* @access private
* @var string
*/
var $dbConn;
/**
* Stores error messages for connection errors
* @access private
* @var string
*/
var $connectError;
/**
* MySQL constructor
* @param string host (MySQL server hostname)
* @param string dbUser (MySQL User Name)
* @param string dbPass (MySQL User Password)
* @param string dbName (Database to select)
* @access public
*/
function MySQL ($host,$dbUser,$dbPass,$dbName) {
$this->host=$host;
$this->dbUser=$dbUser;
$this->dbPass=$dbPass;
$this->dbName=$dbName;
$this->connectToDb();
}
/**
* Establishes connection to MySQL and selects a database
* @return void
* @access private
*/
function connectToDb () {
// Make connection to MySQL server
if (!$this->dbConn = @mysql_connect($this->host,
$this->dbUser,
$this->dbPass)) {
trigger_error('Could not connect to server');
$this->connectError=true;
// Select database
} else if ( dbName,$this->dbConn">!@mysql_select_db($this->dbName,$this->dbConn) ) {
trigger_error('Could not select database');
$this->connectError=true;
}
}
/**
* Checks for MySQL errors
* @return boolean
* @access public
*/
function isError () {
if ( $this->connectError )
return true;
$error=mysql_error ($this->dbConn);
if ( empty ($error)...
Respuesta de Jose Peña
1