NOTE will not explain anything about this script because it was something that I was building from another website COPIE and PEGUE said that I only made these two files I do not know where the error is .
THE PROBLEM is that the query is not previewed. Why?
this is the connection file called:
(db_connect_mysql.php)
<?php
$conexion = @mysqli_connect("localhost", "root", "Admin456", "almacen");
if (!$conexion)
{
printf("Error de conexion NO Utililzar 1.", mysqli_connect_error());
}
?>
this is the other file called
(search.php)
<?php
//Archivo de conexión a la base de datos
include_once "db_connect_mysql.php";
//Variable de búsqueda
$consultaBusqueda = $_POST['valorBusqueda'];
//Filtro anti-XSS
$caracteres_malos = array("<", ">", "\"", "'", "/", "<", ">", "'", "/");
$caracteres_buenos = array("& lt;", "& gt;", "& quot;", "& #x27;", "& #x2F;", "& #060;", "& #062;", "& #039;", "& #047;");
$consultaBusqueda = str_replace($caracteres_malos, $caracteres_buenos, $consultaBusqueda);
//Variable vacía (para evitar los E_NOTICE)
$mensaje = "";
//Comprueba si $consultaBusqueda está seteado
if (isset($consultaBusqueda)) {
//Selecciona todo de la tabla mmv001
//donde el nombre sea igual a $consultaBusqueda,
//o el apellido sea igual a $consultaBusqueda,
$consulta = mysqli_query($conexion, "
SELECT * FROM mmv001
WHERE nombre like '%$consultaBusqueda%'
OR apellido LIKE '%$consultaBusqueda%'
");
//Obtiene la cantidad de filas que hay en la consulta
$filas = mysqli_fetch_array($consulta);
//Si no existe ninguna fila que sea igual a $consultaBusqueda, entonces mostramos el siguiente mensaje
if ($filas === 0) {
$mensaje = "<p>No hay ningún usuario con ese nombre y/o apellido</p>";
} else {
//Si existe alguna fila que sea igual a $consultaBusqueda, entonces mostramos el siguiente mensaje
echo 'Resultados para <strong>'.$consultaBusqueda.'</strong>';
//La variable $resultado contiene el array que se genera en la consulta, así que obtenemos los datos y los mostramos en un bucle
while($resultados = mysqli_fetch_array($consulta)) {
$nombre = $resultados['nombre'];
$apellido = $resultados['apellido'];
$edad = $resultados['edad'];
//Output
$mensaje .= '
<p>
<strong>Nombre:</strong> ' . $nombre . '<br>
<strong>Apellido:</strong> ' . $apellido . '<br>
<strong>Edad:</strong> ' . $edad . '<br>
</p>';
};//Fin while $resultados
}; //Fin else $filas
};//Fin isset $consultaBusqueda
//Devolvemos el mensaje que tomará jQuery
echo $mensaje;
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>test-autollenado</title>
<script src="js/jquery-1.9.1.min.js"></script>
<script>
$(document).ready(function() {
$("#resultadoBusqueda").html('<p>JQUERY VACIO</p>');
});
function buscar() {
var textoBusqueda = $("input#busqueda").val();
if (textoBusqueda != "") {
$.post("buscar.php", {valorBusqueda: textoBusqueda}, function(mensaje) {
$("#resultadoBusqueda").html(mensaje);
});
} else {
$("#resultadoBusqueda").html('<p>JQUERY VACIO</p>');
};
};
</script>
</head>
<body>
<center>
<form accept-charset="utf-8" method="POST">
<table>
<tr><td>lol</td>
<td>
<input type="text" name="busqueda" id="busqueda" value="" placeholder="" maxlength="30" autocomplete="off" onKeyUp="buscar();" />
</td>
<table>
<!--<input type="submit" name="submit" value="busqueda" />-->
</table>
</form>
</center>
<div id="resultadoBusqueda"></div>
</body>
</html>
This is the query that you use for the database:
CREATE TABLE 'mmv001' (
'id' int(11) DEFAULT NULL,
'nombre' varchar(30) DEFAULT NULL,
'apellido' varchar(30) DEFAULT NULL,
'edad' int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
-- ----------------------------
-- Records of mmv001
-- ----------------------------
INSERT INTO 'mmv001' VALUES ('1', 'Juan', 'Villa', '33');
This was the tutorial guide that I found and from here it was that I did it:
DOES NOT SHOW ANYTHING when writing in the text box and it does not show any errors