Problem with button Confirm Purchase of my cart

0

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

<?php 
                 $direct = "img/libros/";
                 $sql2 = "SELECT I.ISBN_id,I.titulo,I.imagen,I.precio,U.id,it.idOrdenes,it.libro,it.cantidad,it.usuario FROM lecturas_db.inventario I,lecturas_db.usuarios U,lecturas_db.items it WHERE U.id = 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>
    <div class="imagenProd">
      <img src="<?php echo $direct.$row['imagen'] ?>">
    </div>
    <div class="tituloProd">
      <center><b><?php echo $row['titulo'] ?></b></center>
    </div><br><br>
    <div class="cantidadProd">
      <center><b><?php echo $row['cantidad'] ?></b> unidad/es</center>
    </div><br><br>
    <div class="subtotalProd">
      <center>Subtotal: <b>$<?php $subtotal = $row['precio']*$row['cantidad'];
                        echo $subtotal;
                        $total += $subtotal;
                        ?></b></center>
    </div><br><br>
    <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">
    </div>
  </div><br><br>
  <?php 	
						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>
                            location.href='index.php';
                            </script>";
                        } else {
                            echo "nada";
                        } 
					} 
					$isbn = $row['libro'];
					$cantidadOrdenes = $row['cantidad'];
					$usuario = $row['usuario'];
					$precio = $row['precio'];
					?>
</form>

Confirm Purchase button

<form method="POST">
  <div class="totalProd">
    <center>
      <h3>TOTAL: $
        <?php
                    	echo $total; 
						?>
      </h3>
    </center>
    <input type="submit" name="comprar" value="CONFIRMAR COMPRA">
  </div>
</form>
<?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
source

0 answers