I am making a form in which you can already save perfectly in the mysqli database, and I already get the data in an html. Now what I want is to erase with a button.
The thing is that it deletes, but always the last record, and not which one I select from the list independently. If I select the first or the second one, I always delete the last one, and I want to see what's wrong.
Here is the code from where I get the list, and also has the delete button.
<?php
$consultabla = mysqli_query($conexion, "SELECT * from 001_agendacentral") or die("Error al leer Agenda");
while ($extraido = mysqli_fetch_assoc($consultabla)) {
echo '<tr>
<td>'.$extraido['nombre'].'</td>
<td>'.$extraido['departamento'].'</td>
<td>'.$extraido['puesto'].'</td>
<td>'.$extraido['correo'].'</td>
<td>'.$extraido['telefono'].'</td>
<td>
<form action="admdelete.php?id='.$extraido['id'].'" method="POST">
<input name="id" type="hidden" value="' . $extraido['id'].'"/>
<input type="submit" class="btn btn-warning" value="Borrar"/></td>
</tr>';
}
mysqli_close($conexion);
?>
Here is the file that performs the deletion procedure.
<?php
require_once('../connect.php');
$conexion = mysqli_connect($host,$user,$pass,$db) or die ("Error al conectar");
$conexion->set_charset("utf8");
$id = $_REQUEST['id'];
echo $id;
//Borrado de tabla con el Campo Nombre
$borrar = "DELETE from 001_agendacentral where nombre='$id'" or die("Error al Borrar");
$resultado = mysqli_query($conexion, $borrar) or die ("Error al Borrar");
if ($resultado) {
mysqli_close($conexion);
echo "Borrado Correctamente";
# code...
}
?>
Already the id column exists in the database. In case you wonder why I'm not showing it, it's not necessary.