I need auto to complete several text boxes through a search to a mysql table.
I have found an example that fits my needs, but I can not make it work
The form is in the index.html file. Entering two digits in the field "registration" makes a query to the database and shows a drop down with the matching results. This is done with the file buscaralumno.php.
This part works for me, when I enter the 2 digits I will see the drop-down with the coincidences and when selecting one of them, the "enrollment" field will be completed, but the other 3 text fields will not be completed.
The auto attendant completing the other 3 fields is the student.php file so I assume that error is in this file.
I do not see any type of error.
I appreciate your comments.
Greetings
index.hml
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js"></script>
<link href="css/jqueryui.css" type="text/css" rel="stylesheet"/>
<script>
$(document).ready(function(){
$( "#matricula" ).autocomplete({
source: "buscaralumno.php",
minLength: 2
});
$("#matricula").focusout(function(){
$.ajax({
url:'alumno.php',
type:'POST',
dataType:'json',
data:{ matricula:$('#matricula')}
}).done(function(respuesta){
$("#nombre").val(respuesta.nombre);
$("#paterno").val(respuesta.paterno);
$("#materno").val(respuesta.materno);
});
});
});
</script>
</head>
<body>
<form>
<label for="matricula">Matricula:</label>
<input type="text" id="matricula" name="matricula" value=""/>
<label for="nombre">Nombre:</label>
<input type="text" id="nombre" name="nombre" value=""/>
<label for="paterno">Paterno:</label>
<input type="text" id="paterno" name="paterno" value=""/>
<label for="materno">Materno:</label>
<input type="text" id="materno" name="materno" value=""/>
</form>
</body>
</html>
buscaralumno.php
<?php
$conexion = new mysqli('localhost','tabla','111111','pruebas',3306);
$matricula = $_GET['term'];
$consulta = "select matricula FROM tblalumno WHERE matricula LIKE
'%$matricula%'";
$result = $conexion->query($consulta);
if($result->num_rows > 0){
while($fila = $result->fetch_array()){
$matriculas[] = $fila['matricula'];
}
echo json_encode($matriculas);
}
?>
alumno.php
<?php
$matricula = $_POST['matricula'];
$conexion = new mysqli('localhost','tabla','111111','pruebas',3306);
$consulta = "SELECT nombre,paterno,materno FROM tblalumno WHERE matricula
= '$matricula'";
$result = $conexion->query($consulta);
$respuesta = new stdClass();
if($result->num_rows > 0){
$fila = $result->fetch_array();
$respuesta->nombre = $fila['nombre'];
$respuesta->paterno = $fila['paterno'];
$respuesta->materno = $fila['materno'];
}
echo json_encode($respuesta);
?>