Save fields of the selected table by checkbox in Mysql made in PHP

2

Good afternoon I am new again in the forum, help me with a problem that I have, I want to save the rows of the table that has been selected by checkbox in Mysql made in PHP, I need to save the id of the product, and the amount in My Mysql database has been tried in several ways but I can not do it, if I save the product id or id (id_prod_serv) but it does not keep me well the quantity or quantities of those products, it saves me the quantities but not in the correct order , if I choose all the products if it keeps me well, but if they are not in order it is not saved correctly. This is my code: This is my SELECT

<?php
        $query = "select B.id_paquete,A.id_prod_serv,A.nombre,B.precio_unitario FROM tb_productos_servicios A JOIN tb_paquetes B ON A.id_prod_serv = B.id_prod_serv JOIN tb_categorias C ON B.id_categoria=C.id_categoria where B.id_categoria=1";
        $res = mysqli_query($con, $query);
        $query3 = "Select * from tb_eventos";
        $res3 = mysqli_query($con, $query3);
?>

The Table:

<table class="table" id="tb1" table-bordered>
  <thead>
    <tr class="warning">
      <th><input type="checkbox" onclick="marcar(this);" /></th>
      <th>Productos</th>
      <th>Precio por unidad</th>
      <th>Cantidad</th>
      <th>Precio por producto</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <?php while ($row2 = mysqli_fetch_array($res)) {
      $id = $row2['id_paquete'];
      $nom = $row2[2];
      $pre = $row2[3];
      ?>
        <tr>
          <td class='col-xs-1'><input type="checkbox" name="idproduc[]" value="<?php echo $row2['id_prod_serv']; ?>"></td>
          <td class='col-xs-2'>
            <?php echo $nom; ?>
          </td>
          <td class='col-xs-1'>
            <div class="pull-right"><input type="number" name="val1" class="form-control monto input" style="text-align:right" value="<?php echo $pre; ?>" />
            </div>
          </td>
          <td class='col-xs-1'>
            <div class="pull-right"><input type="text" id="val2" name="valu[]" class="form-control monto input" style="text-align:right" value="" />
            </div>
          </td>
          <td class='col-xs-1'>
            <div class="pull-right"><input type="number" class="form-control monto total" value="0" readonly/>
            </div>
          </td>
        </tr>


        <?php } ?>
        <tr>
          <td></td>
          <td></td>
          <td></td>
          <td>
            Total
          </td>
          <td class='col-xs-1'>
            <div class="pull-right"><input type="number" class="form-control monto totales" value="0" disabled>
            </div>
          </td>
        </tr>
  </tbody>
</table>

This is my insert:

<?php

require_once("conexion.php");
require_once("db.php");
if (isset($_POST['enviar_per'])) {
    //Si las variables existen (isset) y estan llenos(!empty)
    if (isset($_POST['val']) && !empty($_POST['val']) && isset($_POST['fecha']) && !empty($_POST['fecha']) && isset($_POST['horas_per']) && !empty($_POST['horas_per']) && isset($_POST['cant']) && !empty($_POST['cant']) && isset($_POST['ci']) && !empty($_POST['ci']) && isset($_POST['nom']) && !empty($_POST['nom']) && isset($_POST['email']) && !empty($_POST['email']) && isset($_POST['telef']) && !empty($_POST['telef']) && isset($_POST['direc']) && !empty($_POST['direc'])) {
        mysqli_query($con, "INSERT INTO tb_cotizacion_cabecera (id_evento,fecha_registro,fecha_evento,hora,cant_personas,cedula_cliente,nombre,email,telefono,direccion,estado) VALUES ('$_POST[val]',NOW(),'$_POST[fecha]','$_POST[horas_per]','$_POST[cant]','$_POST[ci]','$_POST[nom]','$_POST[email]','$_POST[telef]','$_POST[direc]','activo')");
        $primero = $_POST['idproduc'];
        $segundo = $_POST['valu'];
        $conx = mysqli_connect($DB_HOST, $DB_USER, $DB_PASS) or die("imposible conectarse: " . mysqli_error($conx));
        mysqli_select_db($conx, $DB_NAME)or die("Problemas al conectar la bd");
        foreach ($primero as $k => $v) {
            $obtener_segundo = $segundo[$k];
                $sql = mysqli_query($conx, "INSERT INTO tb_cotizacion_detalle (id_cotizacion,id_prod_serv,cantidad) VALUES ($con->insert_id,'$v','$obtener_segundo')") or die(mysqli_error($conx));          
        }
        echo '<p style="color:green; background: #ECEFF0; margin-left:100px;">Datos guardados correctamentes</p>';
        mysqli_close($con);
        mysqli_close($conx);
    } else {
        echo '<p style="color:red; margin-left:100px; background: #ECEFF0">No se guardaron sus datos</p>';
    }
}
?>
    
asked by Josue Bryan 24.06.2018 в 02:05
source

0 answers