
Código
<?php $datos=$_SESSION['carrito']; $total=0; for($i=0; $i<count($datos);$i++){ ?> <div class="producto"> <img src="productos/<?php echo $datos['$i']['Imagen']; ?>"><br/> <span><?php echo $datos[$i]['Nombre'];?></span><br/> <span>Precio: <?php echo $datos[$i]['Precio'];?></span><br/> <span>Cantidad: <input type="text" value="<?php echo $datos[$i]['Cantidad'];?>"></span> <span>Subtotal: <?php echo $datos[$i]['Cantidad']*$datos[$i]['Precio'];?></span> </div> <?php $total= $total + ($datos[$i]['Cantidad']*$datos[$i]['Precio']); } } else { echo '<h2>No has metido nada en el carrito de compras</h2>'; } echo '<h2>Total: '.$total.'</h2>'; ?> <a href="./">Ver catalogo</a>
El resultado cuando lo ejecuto:
Notice: Undefined variable: total in C:\xampp\htdocs\htdocs\carrito\carritodecompras.ph p on line 39
La maldita línea 39 es la que contiene echo '<h2>Total: '.$total.'</h2>';
¡Ayudaaaaaaaa!
