-1

I'm trying to create a form that when we select the value on the autocomplete field it will fill another field, autocomplete is working fine but I can't make it fill the second field, can someone guide me a little bit?

Here is my .php

 
// Create database connection 
$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['label'] = $user['Contrato'];
      $res['cliente'] = $user['cliente'];
   array_push( $return_arr, $res );
     }
    } else {
      $res = array();
    }
    //return json res
    echo json_encode($res),"\n";;
}

Here's my jQuery


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

</script>
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 21 '22 at 12:05
  • Whatever you do, do not use that PHP code. You are learning bad practices that will make your life with PHP really difficult. – Dharman May 21 '22 at 12:06
  • Questions that ask "please help me" tend to be looking for highly localized guidance, or in some cases, ongoing or private assistance, which is not suited to our Q&A format. It is also rather vague, and is better replaced with a more specific question. Please read [Why is "Can someone help me?" not an actual question?](//meta.stackoverflow.com/q/284236). – Dharman May 21 '22 at 12:06
  • Ok i completely understand what you said, i will keep that in mind, and will try to find other options for the PHP Code, related to the jquery, i really dont know what am i doing wrong, thanks anyway – HAPPYHELL May 23 '22 at 09:16
  • Im pretty sure my problem is on the .php im retrieving all values and its showing them on the autocomplete – HAPPYHELL May 24 '22 at 00:04
  • no one can give at least a tip? or point the direction? – HAPPYHELL May 25 '22 at 07:50
  • It's just not a very useful question. It has a terrible title and poor problem explanation. People are not interested in it. – Dharman May 25 '22 at 07:52

0 Answers0