2
I am a beginner and wanted to create a function that would return me from the name Cpf, user and password of the person in the system. Where the name and Cpf fields belong to the user table and the user and password fields belong to users.
Way I tried and failed
<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);
}
I tried to leave the same script and only change my select after creating the view and persists error .
– Victor
I created an SQL script that basically illustrated what I tried to explain (I didn’t use view as it is not so necessary at the time)
– Walter Felipe
it would take a javascript like the one I mentioned to fill in the next fields
– Victor
this Insert I made you can adapt to your code
– Walter Felipe
this select I made, just put a php variable in the middle
– Walter Felipe
in case using this code within my Function.php does not give, I think I need to search a new script to fill all data from a field
– Victor