1
I’m trying to make an autocomplete form, however so far it doesn’t work, I don’t know if anyone can identify the error
<div class="form-group">
<label class="control-label col-sm-4" for="Nome"> Nome </label>
<div class="col-sm-6">
<input type="text" class="form-control " id="Nome" autocomplete="on" placeholder="Digite o nome do terceiro" name="Nome">
</div>
<span class='msg-erro msg-Nome'></span>
</div>
<script>
$(document).ready(function(){
$('#Nome').typeahead({
source: function(sql, res)
{
$.ajax({
url:"Includes/search.php",
method:"POST",
data:{sql:sql},
dataType:"json",
success:function(data)
{
result($.map(data, function(item){
return item;
}));
}
})
}
});
});
</script>
search php.
<?php
$request = mysqli_real_escape_string($lig, $_POST["sql"]);
$sql = " SELECT * FROM Terceiros WHERE Nome LIKE '%".$request."%' ";
$res=$lig->query($sql);
$data = array();
if(mysqli_num_rows($res) > 0)
{
while($lin = mysqli_fetch_assoc($res))
{
$data[] = $lin["Nome"];
}
echo json_encode($data);
}
?>
You need to be more specific in your question, see these links: How to ask a good question? and How to create a Minimum, Complete and Verifiable example.
– Leonardo Barros
question, where is your
<form>
? php cannot read anything that is not inside aform
– riki481
my form is higher up like this: <form class="form-horizontal"method="POST" action="index.php? cmd=addter2" onsubmit = "Return validatorRegisto(this)"> </form>
– Someone