Esta es la fuction:
Código PHP:
function imprime_carrito(){
$suma = 0;
echo '<FORM ACTION="insertar_pedido.php" enctype="multipart/form-data" method="post">
<table border=1 cellpadding="4" width="100%" align="center" bordercolor="#000000">
<tr bordercolor="#1D3A62">
<td class="titulo_menu" align="center">Cantidad</td>
<td class="titulo_menu" align="center">Referencia</td>
<td class="titulo_menu" align="center">Precio (unidad)</td>
<td class="titulo_menu" align="center">Acción</td>
</tr>';
for ($i=0;$i<$this->num_productos;$i++){
if($this->array_id_prod[$i]!=0){
echo '<tr bordercolor="#000000">';
echo "<td class='volver'><input name='textfield' type='text' name='cantidad' id='cantidad' size='3' maxlength='5' value='1' style='height:19px'></td>";
echo "<td class='texto'>" . $this->array_referencia_prod[$i] . "<input type='hidden' name='referencia' id='referencia' value='". $this->array_referencia_prod[$i] ."'></td>";
echo "<td class='texto' align='center'>" . $this->array_precio_prod[$i] . "<input type='hidden' name='precio' id='precio' value='". $this->array_precio_prod[$i] ."'><input type='hidden' name='estado' id='estado' value='on'></td>";
echo "<td><a href='eliminar_producto.php?linea=$i'>Eliminar producto</td>";
echo '</tr>';
$suma += $this->array_precio_prod[$i];
}
}
//muestro el total
echo "<tr></td><td><td class='texto'><b>TOTAL (€):</b></td><td class='texto' align='center'> <b>$suma</b></td><td bordercolor='#FFFFFF'> </td></tr>";
//total más IVA
echo "<tr bordercolor='#FFFFFF'><td bordercolor='#FFFFFF' colspan='4' align='center' class='volver'><input type='submit' name='boton' value='realizar pedido' style='height:17px' /></td></tr>";
echo "</table>";
}
Código PHP:
<?php
//Conexion
include("conex.php");
//Valores
$link=Conectarse();
$pedido=$_POST['pedido'];
$cantidad=$_POST['cantidad'];
$referencia=$_POST['referencia'];
$precio=$_POST['precio'];
$estado=$_POST['estado'];
//Consulta para actualizar
mysql_query("insert into pedidos (pedido,cantidad,referencia,precio,id,estado,fecha) values ('','$cantidad','$referencia','$precio','".$_SESSION['id_usuario']."','$estado',NOW())",$link);
//Cerramos la conexion a DB
header("location: productos.php");
?>