I have a table made where it shows me records of a database in mysql.In the table for each record is created a button that is called delete and what I want to get is that by clicking this record is deleted.
I have this code made in usuarios.php
<?php
include_once('conexion.php');
$consulta = consultausu();
?>
between the first php code and the following is web design
<?php
while($variable = $consulta->fetch_assoc())
{
?>
<tr>
<td><?php echo $variable['nombre']; ?></td>
<td><?php echo $variable['apellido']; ?></td>
<td><?php echo $variable['correo']; ?></td>
<td><?php echo $variable['contrasena']; ?></td>
<td>
<form>
<input name="btneliminar" type="button" value="Eliminar" type="submit" class="btn btn-primary offset-2" onclick = "consultaeli();" />
</form>
</td>
</tr>
<?php
}
?>
conexion.php
<?php
//CONECTAMOS CON LA BBDD
$conexion = new mysqli("localhost", "root", "", "discografica");
if ($conexion->connect_errno) {
echo "Fallo al conectar a MySQL: (" . $conexion->connect_errno . ") " . $conexion->connect_error;
}
$consultaeliminar='';
function consultaeli(){
global $conexion, $consultaeliminar;
$borrar = "DELETE FROM usuarios where nombre='$variable'";
return $conexion->query($borrar);
}
}