Ver Mensaje Individual
  #1 (permalink)  
Antiguo 02/01/2014, 15:53
Avatar de Linton
Linton
 
Fecha de Ingreso: diciembre-2011
Ubicación: Viena
Mensajes: 1.213
Antigüedad: 12 años, 4 meses
Puntos: 55
Fallo de variable $total en carrito de compra

¿Alguien vislumbra dónde falla este código?

Código PHP:
Ver original
  1. <?php
  2.     if(isset($_SESSION['carrito'])){
  3.         $datos=$_SESSION['carrito'];
  4.         $total=0;
  5.         for($i=0; $i<count($datos);$i++){
  6.         ?>
  7.     <div class="producto">
  8.         <img src="productos/<?php echo $datos['$i']['Imagen']; ?>"><br/>
  9.         <span><?php echo $datos[$i]['Nombre'];?></span><br/>
  10.         <span>Precio: <?php echo $datos[$i]['Precio'];?></span><br/>
  11.         <span>Cantidad: <input type="text" value="<?php echo $datos[$i]['Cantidad'];?>"></span>
  12.         <span>Subtotal: <?php echo $datos[$i]['Cantidad']*$datos[$i]['Precio'];?></span>
  13.            
  14.     </div>
  15.         <?php
  16.         $total= $total + ($datos[$i]['Cantidad']*$datos[$i]['Precio']);
  17.         }
  18.         } else {
  19.             echo '<h2>El carrito de compras está vacío</h2>';
  20.             }
  21.             echo '<h2>Total: '.$total.'</h2>';
  22.             ?>
  23.                 <a href="./">Ver catálogo</a>

Cuando lo ejecuto, sale esto:
Notice: Undefined variable: total in C:\xampp\htdocs\htdocs\carrito\carritodecompras.ph p on line 39
La dichosa línea 39 es la que contiene echo '<h2>Total: '.$total.'</h2>';

Gracias por la ayuda, un saludo.