I got a code that when something is typed in the input, it loads the data without refresh on the page, but I wanted to do this through button, thus avoiding bugs.
I am not able to convert the code to execute with button.
My .js code:
$("#busca").keyup(function(){
var campo = $("#busca").val();
$.post('processa.php', {campo: campo},function(data){
$("#result").html(data);
});
});
processa.php
$campo = $_POST['campo'];
$result = "SELECT * FROM usuario WHERE nome = '$campo'";
$resultado = mysqli_query($conn, $result);
if($resultado->num_rows != 0 ){
while($row = mysqli_fetch_assoc($resultado)){
echo $row('nome');
echo $row(senha);
echo $row(data_nasc);
} else {
"Nenhum usuário encontrado"
}
form:
<form action="processa.php" method="POST">
<input type="text" class="form-control" name="busca" placeholder="Nome">
<button id="executar" type="button" class="btn btn-warning"">Buscar</button>
</form>