-2

I'm trying to create a form that when we select the value on the autocomplete field it will fill some other fields, autocomplete is working but I can't make it fill the second field, can someone point me the way, I think is something with my PHP file?

$db = new mysqli($dbHost, $dbUsername, $dbPassword, $dbName); 
 
// Check connection 

if (isset($_GET['term'])) {
     
   $query = "SELECT * FROM registo_obra WHERE Contrato LIKE '{$_GET['term']}%' LIMIT 25";
    $result = mysqli_query($db, $query);
 
    if (mysqli_num_rows($result) > 0) {
     while ($user = mysqli_fetch_array($result)) {
      $res[] = $user['Contrato'];
      $res[] = $user['cliente'];
      $res[] = $user['descricao'];
       
       

   array_push( $return_arr, $res );
     }
    } else {
      $res = array();
    }
    //return json res
    echo json_encode($res),"\n";; 
}

Here is my jQuery

 
<script>
$(function() {
    $("#Editbox1").autocomplete({
        source: "data2.php",
select: function (event, ui) {
    var item = ui.item;
    if(item) {

     $("#wb_Text1").html(item.cliente);
        $("#wb_Text2").html(item.descricao);            
                    }
                }
    });
    });


  
</script>
Dharman
  • 26,923
  • 21
  • 73
  • 125
HAPPYHELL
  • 13
  • 7
  • **Warning:** You are wide open to [SQL Injections](https://php.net/manual/en/security.database.sql-injection.php) and should use parameterized **prepared statements** instead of manually building your queries. They are provided by [PDO](https://php.net/manual/pdo.prepared-statements.php) or by [MySQLi](https://php.net/manual/mysqli.quickstart.prepared-statements.php). Never trust any kind of input! Even when your queries are executed only by trusted users, [you are still in risk of corrupting your data](http://bobby-tables.com/). [Escaping is not enough!](https://stackoverflow.com/q/32391315) – Dharman May 24 '22 at 09:35
  • I get that, im still learning, for now i just want to understand how to this in a manner that i understand and then i will understand how to improve and get my info safe, related to my question, may i have some guidance? – HAPPYHELL May 24 '22 at 09:55
  • Where is `$return_arr` defined? – Twisty Jun 03 '22 at 21:25

0 Answers0