<?php
session_start();
require_once("conexion.php");
$arreglo=$_SESSION['carrito'];
		$numeroventa=0;
		$consulta=mysql_query("select * from compras order by numeroventa DESC limit 1") or die(mysql_error());	
		while (	$fila=mysql_fetch_array($consulta)) {
					$numeroventa=$fila['numeroventa'];	
		}
		if($numeroventa==0){
			$numeroventa=1;
		}else{
			$numeroventa=$numeroventa+1;
		}
		for($i=0; $i<count($arreglo);$i++){
			mysql_query("insert into compras (numeroventa, imagen,nombre,precio,cantidad,subtotal) values(
				".$numeroventa.",
				'".$arreglo[$i]['Imagen']."',
				'".$arreglo[$i]['Nombre']."',	
				'".$arreglo[$i]['Precio']."',
				'".$arreglo[$i]['Cantidad']."',
				'".($arreglo[$i]['Precio']*$arreglo[$i]['Cantidad'])."'
				)")or die(mysql_error());
		}
		unset($_SESSION['carrito']);
		header("Location: ./mostrar.php");
?>