Ver Mensaje Individual
  #1  
Antiguo 05-07-2006
boss fede boss fede is offline
Registrado
 
Registrado: sep 2005
Posts: 4
Reputación: 0
boss fede Va por buen camino
carrito de compras

Saludos a todos!!!

este script lo encontre en Manual de PHP de WebEstilo.com

Código PHP:
<?php
session_start
();
session_register('itemsEnCesta');
$item=$_POST['item'];
$cantidad=$_POST['cantidad'];
$itemsEnCesta=$_SESSION['itemsEnCesta'];
if (
$item){
if (!isset(
$itemsEnCesta)){
$itemsEnCesta[$item]=$cantidad;
}else{
foreach(
$itemsEnCesta as $k => $v){
if (
$item==$k){
$itemsEnCesta[$k]+=$cantidad;
$encontrado=1;
}
}
if (!
$encontrado$itemsEnCesta[$item]=$cantidad;
}
}
$_SESSION['itemsEnCesta']=$itemsEnCesta;
?>
<html>
<body>
<tt>
<form action="<?=$PHP_SELF."?".$SID?>" method="post">
Dime el producto <input type='text' name="item" size='20'><br>
Cuantas unidades <input type='text' name='cantidad' size='20'><br>
<input type="submit" value="Añadir a la cesta"><br>
</form>
<?
if (isset($itemsEnCesta)){
echo
'El contenido de la cesta de la compra es:<br>';
foreach(
$itemsEnCesta as $k => $v){
echo 
'Artículo: '.$k.' ud: '.$v.'<br>';
}
}
?>
</tt>
</body>
</html>
Al ejecutarlo salen los siguientes errores.

Notice: Undefined index: item in D:\programas\Abyss Web Server\htdocs\pruebas\cesta.php on line 4

Notice: Undefined index: cantidad in D:\programas\Abyss Web Server\htdocs\pruebas\cesta.php on line 5

El problema es que no funciona en mi maquina, pero al subirla a algun sitio de hospedaje si funciona.
No tengo problemas con session_start() ni session_register(), el problema son las variables item y cantidad, que me aconsejan hacer?
trabajo con php5
Mil gracias!!!!

Última edición por dec fecha: 06-07-2006 a las 00:01:33.
Responder Con Cita