I am a beginner and wanted to create a function that would return me from the name of the cpf, user and password of the person in the system. Where the name and cpf fields belong to the users table and the user and password fields belong to users.
Way I tried and did not succeed
<script type='text/javascript'>
$(document).ready(function(){
$("input[name='nome']").blur(function(){
var $cpf = $("input[name='cpf']");
var $usuario = $("input[name='usuario']");
var $senha = $("input[name='senha']");
$.getJSON('function.php',{
nome: $( this ).val()
},function( json ){
$cpf.val( json.cpf );
$usuario.val( json.usuario );
$senha.val( json.senha );
});
});
});
</script>
My function.php
function retorna($nome, $conn){
$result = "SELECT CPF, USUARIO, SENHA FROM USUARIOS A INNER JOIN USUAR B ON B.NOME = A.NOME WHERE nome = '$nome' LIMIT 1";
$resultado = mysqli_query($conn, $result);
if($resultado->num_rows){
$row = mysqli_fetch_assoc($resultado);
$valores['cpf'] = $row['cpf'];
$valores['usuario'] = $row['usuario'];
$valores['senha'] = $row['senha'];
}else{
$valores['cpf'] = '';
$valores['usuario'] = '';
$valores['senha'] = '';
}
return json_encode($valores);
}
if(isset($_GET['nome'])){
echo retorna($_GET['nome'], $conn);
}