Ver Mensaje Individual
  #1 (permalink)  
Antiguo 16/04/2016, 00:42
Avatar de aviweb2015
aviweb2015
 
Fecha de Ingreso: abril-2016
Ubicación: venezuela
Mensajes: 215
Antigüedad: 8 años, 11 meses
Puntos: 1
Información atrapar variable

hola amigos como puedo atrapar la variable total para guardarla en la bd


archivo carrito

Código PHP:
Ver original
  1. <?php
  2.       $total=0;
  3.       if(isset($_SESSION['carrito'])){
  4.       $datos=$_SESSION['carrito'];
  5.      
  6.       $total=0;
  7.       for($i=0;$i<count($datos);$i++){
  8.        
  9.   ?>
  10.         <div class="producto">
  11.  
  12.           <center>
  13.             <img src="./imagenes/<?php echo $datos[$i]['Imagen'];?>"><br>
  14.             <span ><?php echo $datos[$i]['Descripcion'];?></span><br>
  15.             <span>Precio: <?php echo $datos[$i]['Precio'];?> Bsf</span><br>
  16.             <span>Cantidad:
  17.               <input type="text" value="<?php echo $datos[$i]['Cantidad'];?>"
  18.               data-precio="<?php echo $datos[$i]['Precio'];?>"
  19.               data-id="<?php echo $datos[$i]['Id'];?>"
  20.               class="cantidad">
  21.             </span><br>
  22.             <span class="subtotal">Subtotal:<?php echo $datos[$i]['Cantidad']*$datos[$i]['Precio'];?></span><br>
  23.             <a href="#" class="eliminar" data-id="<?php echo $datos[$i]['Id']?>">Eliminar</a>
  24.           </center>
  25.         </div>
  26.       <?php
  27.         $total=($datos[$i]['Cantidad']*$datos[$i]['Precio'])+$total;//total del pedido
  28.       }
  29.        
  30.       }else{
  31.         echo '<center><h4>No has añadido ningun producto</h4></center>';
  32.       }
  33.       echo '<center><h4 id="total">Total Bsf: '.$total.'</h4></center>';
  34.       if($total!=0){
  35.           echo '<center><a href="validar_compra.php" class="aceptar">Finalizar Pedido</a></center>;';
  36.       }
  37.      
  38.     ?>


archivo validar compra


Código PHP:
Ver original
  1. <?php
  2. include "conexion.php";
  3.         $arreglo=$_SESSION['carrito'];
  4.        
  5.         $numeroventa=0;
  6.  
  7.         $re=mysql_query("select * from compras order by numeroventa DESC limit 1") or die(mysql_error());  
  8.         while ( $f=mysql_fetch_array($re)) {
  9.                     $numeroventa=$f['numeroventa'];
  10.         }
  11.         if($numeroventa==0){
  12.             $numeroventa=1;
  13.         }else{
  14.             $numeroventa=$numeroventa+1;
  15.         }
  16.         for($i=0; $i<count($arreglo);$i++){
  17. mysql_query("insert into compras
  18. (numeroventa, imagen,descripcion,precio,cantidad,subtotal,total) values(
  19.                 ".$numeroventa.",
  20.                 '".$arreglo[$i]['Imagen']."',
  21.                 '".$arreglo[$i]['Descripcion']."', 
  22.                 '".$arreglo[$i]['Precio']."',
  23.                 '".$arreglo[$i]['Cantidad']."',
  24.                 '".($arreglo[$i]['Precio']*$arreglo[$i]['Cantidad'])."'
  25.                 )")or die(mysql_error());
  26.         }
  27.  
  28. //total del pedido
  29.  
  30. unset($_SESSION['carrito']);
  31. header("Location:final.php");
  32.  
  33. ?>


gracias espero su ayuda
__________________
yoclens avilan