How to create model to delete and modify data [closed]

-3
****<!DOCTYPE html>
<html>
<head>
  <title></title>
   <link rel="stylesheet" href="../css3/bootstrap.min.css">
</head>
<body>
<center><h3>LISTADO DE MATERIALES DEL ENCARGADO</h3></center>
 <div  class="E1" id="general">
      <table class="table table-bordered table-hover" id="tabla">
        <tr class="success">          
          <th></th>
          <th></th>
          <th></th>
          <th>Encardado : <?php echo $_SESSION['nombre'];?></th>              
          <th><a href="cerrarSeccion.php">Cerrar Seccion</a></th>
        </tr>
      </table>
  </div>
 <section class="col-md-10 col-md-offset-1"><br><br>
 <a href="ingresoMaterial.php" class="btn btn-primary">Ingrese Un Material</a>
 <a href="../pdf/pdfReporte.php" class="btn btn-primary">Imprimir PDF</a>
    <div  class="E1" id="general">
      <table class="table table-bordered table-hover" id="tabla">
        <tr class="success">      
          <th>Materiales</th>
          <th>Descripcion</th>
          <th>Cantidad</th>
          <th>Precio</th>
          <th>Costo Total por Unidad</th>
          <th>Operacion</th>  
          <th></th>              
        </tr>
    <?php    
        include('../configuracion/conexion.php');
        $conexion = conectarse(); 
        $conector = " SELECT nombre, descripcion, cantidad, precio, cantidad*precio FROM materiales"; 
                $id= $_SESSION['id'];  
            $resultado = mysqli_query($conexion,$conector);
            $contador = 0;
            while ($row = $resultado->fetch_array(MYSQLI_NUM)){   
                echo "<tr>";
                echo "<td>$row[0]</td>"; 
                echo "<td>$row[1]</td>";  
                echo "<td>$row[2]</td>";  
                echo "<td>$row[3]</td>";
                echo "<td>$row[4]</td>";
                $contador = $contador + $row[4];

                  // ESTOS SON LOS BOTONES PERO NO SE SI SE USA ASI
                echo "<td>
                  <form method='POST' action='logicaEliminar.php'>
                    <button type='submit' name='$row[0]'>Eliminar</button>
                  </form>
                </td>";
                echo "<td>
                  <form method='POST' action='logicaCrudM.php'>
                    <button type='submit' name='$row[0]'>Modificar</button>
                  </form>
                </td>";   
                echo "</tr>";  
                }
                $conector2 = "UPDATE usuarios SET presupuesto='$contador' WHERE id='$id' ";    
                $resultado2 = mysqli_query($conexion,$conector2);


    ?>  
    </table>
    <div  class="E1" id="general">
      <table class="table table-bordered table-hover" id="tabla">
        <tr class="success">          
          <th>Presupuesto : <?php echo $contador;?> Bolivares</th>              
        </tr>
      </table>
    </div>
</body>
</html>****

    
asked by Gamez 28.06.2017 в 00:34
source

1 answer

1

It could be done in many other ways (Ajax, a get directly to the php to delete / modify) but I will put the code for the forms you are using.

In the form that you enter for each delete button, you would need to add a field that would receive the php logicaEliminar.php as a parameter, in which you must indicate the ID of the element to be deleted.

<form method='POST' action='logicaEliminar.php'>
  <button type='submit' name='$row[0]'>Eliminar</button>
  <input type='hidden' name='id' value='<?=$row['id'];?>'>
</form>

Also, in the SELECT that you throw against the database, you should take the ID or primary key from the table of each element, in order to be able to enter it in the hidden input.

$conector = " SELECT ID, nombre, descripcion, cantidad, precio, cantidad*precio FROM materiales";

It would be necessary to review the logic code Delete.php to see how you have it.

    
answered by 28.06.2017 в 14:35