I have a table with data and some checkboxs corresponding to their respective row. If I select one or several checkboxs and click Delete , you will ask me in a " confirm () " if I want to delete them. If I click on " Accept ", it deletes them correctly and if I deny the question, that is, I choose the option " Cancel " cancels the operation but keeps the checkbox active previously chosen.
I wish that by pressing " Cancel ", the active checkboxs will be deleted.
HTML Code:
<div class="boton_eliminar" class="table-responsive" align="left">
<font face="verdana">
<b><input type="submit" style="width:200px; height:28px;" name="eliminar_cabanas" id="eliminar_cabanas" onclick="return confirm('¿Deseas realmente eliminar estas cabañas?');" value="Eliminar cabañas" /></b>
</font>
</div>
PHP Code:
<?php
//Si pulsamos el botón "Eliminar cabañas"...
if(isset($_POST['eliminar_cabanas'])){
if(empty($_POST['marcados'])){
echo "<h4><center>No se ha seleccionado ninguna cabaña.</center></h4>";
}else{
foreach($_POST['marcados'] as $valor){
//Nos conectamos a la base de datos.
$conexion = mysqli_connect("localhost", "root", "root", "osmarrural");
//Realizamos la consulta.
$sql = sprintf("DELETE FROM cabanas WHERE idcabana='%d'", $valor);
$resultado = mysqli_query($conexion, $sql);
}
echo "<meta http-equiv=\"refresh\" content=\"0; URL=panel_administrador.php\">";
}
}
?>