I want that when you press delete incident, an alert will appear to make sure that it is deleted or not, the problem is that whenever I press cancel, the incident is deleted. Can somebody help me?
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Si se ha pulsado el boton de eliminar incidencia
if (isset($_POST["eliminarInci"])) {
// Capturamos el valor de $codTarea del campo oculto del formulario
$codTarea = $_POST["codigoTarea"];
// Borramos la tarea seleccionada
require_once('funciones/conexion.php');
try {
$deleteIncidencia = "DELETE FROM tareas WHERE COD_TAREA = ?";
$preparada = $db->prepare($deleteIncidencia);
$preparada->execute(array($codTarea));
// Cuando la consulta se ejecute se elimina
if ($preparada) {
print "
<script>
var result = window.confirm('¿Seguro que quieres borrar esta incidencia?');
if(result){
window.location = 'admin.php';
}
else{
window.location = 'admin.php';
}
</script>";
exit;
}
} catch (Exception $e) {
echo "Error: " . $e->getMessage();
}
}
}
?>