Problem with button Confirm Purchase of my cart


Again I ask a question that I have already asked but in a different way, to see if that is how I explain myself better. I have made a cart in constant communication with my database (When the user selects a product it is inserted in a table "items", and it is from this table that I show the products of the cart by means of a while). Now, with my Confirm Purchase button, what I'm looking for is to have the selected products saved in the "Orders" table. The problem is that if I have more than one product selected, only the last aggregate is saved. I want to know how to insert multiple rows in my table with a single sql statement, and how to avoid overwriting my variables. I leave code. WHILE showing selected products

                 $direct = "img/libros/";
                 $sql2 = "SELECT I.ISBN_id,I.titulo,I.imagen,I.precio,,it.idOrdenes,it.libro,it.cantidad,it.usuario FROM lecturas_db.inventario I,lecturas_db.usuarios U,lecturas_db.items it WHERE = it.usuario AND I.ISBN_id = it.libro AND it.usuario = $id";
				 $res = mysqli_query($conexion,$sql2);
                while($row = mysqli_fetch_array($res)) { ?>
<form method="POST" class="Prod">
    <div class="imagenProd">
      <img src="<?php echo $direct.$row['imagen'] ?>">
    <div class="tituloProd">
      <center><b><?php echo $row['titulo'] ?></b></center>
    <div class="cantidadProd">
      <center><b><?php echo $row['cantidad'] ?></b> unidad/es</center>
    <div class="subtotalProd">
      <center>Subtotal: <b>$<?php $subtotal = $row['precio']*$row['cantidad'];
                        echo $subtotal;
                        $total += $subtotal;
    <div class="eliminarProd">
      <input type="hidden" name="isbn" value="<?php echo $row['libro'] ?>">
      <input type="hidden" name="cantidadOrdenes" value="<?php echo $row['cantidad'] ?>">
      <input type="hidden" name="usuario" value="<?php echo $row['usuario'] ?>">
      <input type="hidden" name="precio" value="<?php echo $row['precio'] ?>">
      <input type="hidden" name="id" value="<?php echo $row['idOrdenes'] ?>">
      <input type="submit" value="ELIMINAR" name="eliminar">
						if($_POST['eliminar']) {
						$id_eliminar = intval($_POST['id']);
                        $sql3 = "DELETE FROM lecturas_db.items WHERE idOrdenes = $id_eliminar LIMIT 1";
                        $res1 = mysqli_query($conexion,$sql3);
                        if($res1 > 0) {
                            echo "<script>
                        } else {
                            echo "nada";
					$isbn = $row['libro'];
					$cantidadOrdenes = $row['cantidad'];
					$usuario = $row['usuario'];
					$precio = $row['precio'];

Confirm Purchase button

<form method="POST">
  <div class="totalProd">
      <h3>TOTAL: $
                    	echo $total; 
    <input type="submit" name="comprar" value="CONFIRMAR COMPRA">
<?php if($_POST['comprar']) {
					$fecha = date('l jS \of F Y');
					$sql4 = "INSERT INTO lecturas_db.ordenes(isbn,cantidadOrdenes,usuario,precio,fecha) VALUES('$isbn','$cantidadOrdenes','$usuario','$precio','$fecha')";
					$res2 = mysqli_query($conexion,$sql4);
asked by Juan enriquez 03.12.2018 в 17:10

0 answers