The error tells you that you are trying to access a nonexistent index in an array. In this almost $_POST['buscar']
does not exist.
Do a post debug to know what it contains:
var_dump($_POST);
How all your subsequent code depends on that value that is not reaching you, you will not be able to show anything, you should provide an error message for the user doing the search, both to avoid this type of errors and for the case that you do not recover data when completing the search. In any case, for the error that this position does not exist in post , it would generate a log of internal use and a generic message for the user.
$err = 'No existen datos para la búsqueda actual';
$nombre = (isset($_POST['buscar']))
? $_POST['buscar']
: null;
if ($nombre) {
//Aquí tu consulta a la BD
//
//Comprobar que tienes datos a mostrar
//
//Si hay datos -> Sigues con tu código
//
//Si NO hay datos:
// -> Puedes volver a la vista anterior, supongo que con el formulario de busqueda
// -> Mostrar mensaje de error al usuario (contenido de $err)
} else {
//Generar log de errores de la aplicación (uso interno)
//
//Mostrar mensaje de error al usuario (contenido de $err)
//
}
You have to put the code in the questions and as complete as possible so that you can reproduce the error if possible and give the best solution, I answered with what I had.
I already gave an answer to this type of error in another question, you can consult it here .
Greetings.
Using:
$Nombre = $_POST['buscar'];
When your page reloads for the first time, it looks for the value that contains that index in the Array, logically it does not find it since the array does not have that position created yet and also does not contain any value.
The solution is to execute that line and consult the DB, if there is a value in that ARRAY index. We do this with the following code:
if(isset($_POST['buscar'])){
//Consulta SQL
}
This way the code will only be executed once that index exists in the Array and not in the loading of the page as it happens in your example.