button name

-1

I have a site that I'm doing in PHP, just that I have a question.

I have some while cycles and add buttons only on the button I have

while($row=mysqli_fetch_array($result))
{
$id = $row["ID"];
$Auditor = $row["Auditor"];
$auditoria = $row["Auditoria"];
$Fdeseada = $row["Fdeseada"];
$Flimite = $row["Flimite"];
 echo "<tr>
     <td align='right' class='estilo1'> $id </td>
     <td class='estilo1'> $Auditor </td>
     <td class='estilo1'> $auditoria </td>
     <td class='estilo1'> $Fdeseada </td>
     <td class='estilo1'> $Flimite </td>
         <td class='estilo1'> $row[Estado] </td>
             <td class='estilo1'><A HREF='verEncuesta.php'> Realizar </A></td>
             <td><input type='submit' name='borrar' class='submit' value =".$id."></td>                    
  </tr>";
}
echo "</table>";

that sends me the id to another php file that does the deletion of the line only that my button appears deleted + the ID number and I just want it to say Delete but if I put it Delete it does not delete me because it does not I pass the ID. How can I improve this part?

file delete

if ($_POST["borrar"]) {
    $id = $_POST["borrar"];
    $query = "Delete From tareas Where ID='$id'";
 if ($conexion->query($query) === TRUE) {
 echo "<br />" . "<h2>" . "Tarea eliminada Exitosamente!" . "</h2>";
 echo "<h5>" . "<a href='calendario.php'>Regresar</a>" . "</h5>"; 
 }
 else {
 echo "Error al crear el empreado." . $query . "<br>" . $conexion->error; 
   }
    
}
    
asked by antonio sanchez 03.04.2018 в 19:40
source

2 answers

1

You can add a hidden type input, to show you the hidden field, and in your delete file get that new value $ id = $ _POST ["prodId"];

<input id="prodId" name="prodId" type="hidden" value='".$id."'>

En tus botones:
<td class='estilo1'> $row[Estado] </td>
         <td class='estilo1'><A HREF='verEncuesta.php'> Realizar </A></td>
         <td>
<input id="prodId" name="prodId" type="hidden" value='".$id."'>
<input type='submit' name='borrar' class='submit' value ="borrar">
</td>    
    
answered by 03.04.2018 / 19:51
source
1

I guess it's all within <form method="post" action="eliminar.php"></form> or something similar, assuming that, what you should do is add a <input type="hidden" /> with the name and value you want to remove.

while ($row = mysqli_fetch_array($result)) {
  $id = $row["ID"];
  $Auditor = $row["Auditor"];
  $auditoria = $row["Auditoria"];
  $Fdeseada = $row["Fdeseada"];
  $Flimite = $row["Flimite"];
  echo "<tr>
     <td align='right' class='estilo1'> $id </td>
     <td class='estilo1'> $Auditor </td>
     <td class='estilo1'> $auditoria </td>
     <td class='estilo1'> $Fdeseada </td>
     <td class='estilo1'> $Flimite </td>
     <td class='estilo1'> $row[Estado] </td>
     <td class='estilo1'><A HREF='verEncuesta.php'> Realizar </A></td>
     <td>
       <input type='hidden' name='borrar' value='".$id."' />
       <input type='submit' class='submit' value='borrar' />
     </td>                    
  </tr>";
}
echo "</table>";

Then in the file delete.php should be what you went through to delete the record.

    
answered by 03.04.2018 в 19:55