How to insert the value of a checkbox inside my mysql table?

0

I have a table of requests and what I want to do is an UPDATE that when I check the checkbox of several of them, I update the database that all the selected ones are en route. but I do not understand how to capture the multiple values of the checkboxes and save them in the route column. Thanks

 $query = mysqli_query($con,"SELECT * FROM contribuyente  order by id LIMIT 
 $offset,$per_page");

if ($numrows>0){
  ?>
  <div class="panel-body">
<div class="panel panel-default">
  <form action="checkruta.php" method="post" >
<table class="my-table">

    <tr class="odd gradeX">
     <th>Folio</th>
      <th>Nombre</th>
     <th>Fecha Solicitud</th>
      <th>Solicitud</th>
      <th>Estado</th>
      <th>Fecha reporte</th>
      <th>Seleccionar Ruta</th>
      <th><input type="submit" name="guardar" value="guardar"/></th>

    </tr>
  </thead>
  <tbody>
  <?php
  while($row = $res->fetch_array(MYSQLI_BOTH)){
    ?>
    <tr>
      <td><?php echo $row[0];?></td>
      <td><?php echo $row[1];?></td>
      <td><?php echo $row[6];?></td>
      <td><?php echo $row[7];?></td>
      <td><?php echo $row[8];?></td>
      <td><?php echo $row[10];?></td>
      <?php echo "<td><input type='checkbox' id='cbox1' value='en ruta'> <br></td>";
      ?>

    </tr>
    <?php
  }
  ?>

    
asked by Daniela 29.05.2018 в 22:29
source

1 answer

0

In the last value of each row you could put something like:

<?php echo "<td><input type='checkbox' id='cbox1' name='rutas[]' value='<?php echo $row[0];?>'> <br></td>";?>

And in your script that receives the information you would have something like:

if( !empty( $_POST[ 'rutas' ] ) ) {

foreach( $_POST[ 'rutas' ] as $ruta ) {
    // Aqui se imprimiria el id de la tabla que necesitas actualizar,
   // solo si ese checkbox fue seleccionado       
    echo $ruta; 
}
    
answered by 29.05.2018 в 23:04