The delete function works perfectly by doing the following with the delete button.
<a href="borrar.php?id=<?php echo $persona->id; ?>"><button type="button" class="btn btn-danger" onClick="<?php $identificador = $persona->id; ?>">Eliminar</button></a>
As you may notice, I send a parameter to my file delete.php
<?php
require('conexion.php');
$id = $_GET['id'];
try{
$sql="delete from datos_usuarios where id='$id'";
$execute = $base->query($sql);
header ('Location: index.php');
}catch(Exception $e){
die ('Error no se ah podido eliminar el usuario' . $e->getMessage());
}
Seeing the simplicity of my program, I decided to add a modal bootstrap in which the information of the person I want to eliminate and two buttons is displayed, one to confirm that he is sure to delete the record and the other to cancel said action.
The problem is that I can not find the way to show the information of the person that was selected, it occurred to me that when I clicked on the delete button I stored the id of the record I was trying to delete in the following way. :
<a href="#ventana1" data-toggle="modal"><button class="btn btn-danger btn-xs" onClick="$identificador = $persona->id; ?>" >Eliminar</button></a>
As you can understand, I am a newbie in php and I do not really see any error but I think it has to do with not assigning the value to the variable, well then, without a hug, I enclose all my code. index.php file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title></title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.2/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<?php
include ('conexion.php');
$registros = $base->query('SELECT * FROM DATOS_USUARIOS')->fetchAll(PDO::FETCH_OBJ);
?>
<h3 class="text-center">Registro de usuarios</h3>
<div class="container">
<!--VENTANA MODAL -->
<div class="modal fade" id="ventana1" tabindex="-1" role="dialog" aria-labelledby="" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="">Eliminar usuario</h4>
</div>
<div class="modal-body">
<?php
$resultado = $base->query("select * from datos_usuarios where id='$identificador' limit 1")->fetchAll(PDO::FETCH_OBJ);
foreach($resultado as $rs){
echo "Esta seguro que desea eliminar el usuario <b>" . $rs->nombre . "</b>";
}
?>
</div>
<div class="modal-footer">
<a href="borrar.php?id=<?php echo $identificador; ?>"><button type="button" class="btn btn-danger" data-dismiss="">Eliminar</button></a>
<button type="button" class="btn btn-default" data-dismiss="modal">Cancelar</button>
</div>
</div>
</div>
</div>
<!--END MODAL -->
<div class="row">
<div class="col-lg-8">
<div class="panel panel-default">
<div class="panel-heading">Formulario de registro</div>
<div class="panel-body">
<div class="table table-responsive text-center">
<table class ="table table-bordered table-condensed table-striped table-responsive table-hover">
<thead>
<th>ID</th>
<th>Nombre</th>
<th>Apellido</th>
<th>Direccion</th>
<th>Opciónes</th>
</thead>
<?php
foreach($registros as $persona):?>
<tr>
<td><?php echo $persona->id?></td>
<td><?php echo $persona->nombre?></td>
<td><?php echo $persona->apellido?></td>
<td><?php echo $persona->direccion?></td>
<td>
<a href="actualizar.php"><button class="btn btn-primary btn-xs">Actualizar</button></a>
<a href="#ventana1" data-toggle="modal"><button class="btn btn-danger btn-xs" onClick="$identificador = $persona->id; ?>" >Eliminar</button></a>
<!-- <a href="borrar.php?id=<?php echo $persona->id; ?>"><button type="button" class="btn btn-danger" onClick="<?php $identificador = $persona->id; ?>">Eliminar</button></a> -->
</td>
</tr>
<?php
endforeach;
?>
<tr>
<td></td>
<td><input type="text" name="" value=""></td>
<td><input type="text" name="" value=""></td>
<td><input type="text" name="" value=""></td>
<td><div class="text-center">
<button type="button" name="button" class="btn btn-success btn-xs">Insertar</button>
</div></td>
</tr>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</body>
</html>