Autocomplete - Custom data and display

Autocomplete - Custom data and display

I cannot make it works. There is a Products table (codigo, descripcion, precio, cantidad), typing part of the codigo field should appear the other fields on the list, to select one. However, the list appears with the correct amount of records but with UNDEFINED on every value. 
Any idea about why the script is not taking properly the values sent by search.php ? Thank you !

INDEX.PHP

  1.  <script>
  2.   $( function() {
  3.  
  4.     $( "#codigo" ).autocomplete({
  5.       minLength: 0,
  6.       source: 'search.php',

  7.       focus: function( event, ui ) {
  8.         $( "#codigo" ).val( ui.item.codigo2 );
  9.         return false;
  10.       },

  11.       select: function( event, ui ) {
  12.         $( "#codigo" ).val( ui.item.codigo2 );
  13.         $( "#descri2" ).val( ui.item.descri );
  14.         $( "#precio2" ).html( ui.item.precio);
  15.         $( "#stock2" ).html( ui.item.stock);

  16.         return false;
  17.       }

  18.     })

  19.     .autocomplete( "instance" )._renderItem = function( ul, item ) {
  20.       return $( "<li>" )
  21.         .append( "<div>" + item.codigo2 + "<br>" + item.descri  + "<br>Precio: " + item.precio  + "<br>Stock: " + item.stock + "</div>" )
  22.         .appendTo( ul );
  23.     };


  24.   } );
  25.   </script>
  26. </head>

  27. <body>

  28. <input id="codigo" >
  29. <input type="hidden" id="codigo">
  30. <p id="descri2"></p>
  31. <p id="precio2"></p>
  32. <p id="stock2"></p>



SEARCH.PHP

  1. $con = mysqli_connect(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_NAME);
  2. if( mysqli_connect_error()) echo "Failed to connect to MySQL: " . mysqli_connect_error();

  3. $searchTerm=$_GET['term'];


  4. $query = "SELECT * FROM articulos where codigo_articulo LIKE '%".$searchTerm."%'";
  5. $result = mysqli_query($con, $query);
  6. $data = array();
  7. while ($row = mysqli_fetch_assoc($result)) {
  8. $name = "codigo2: " . '"' . $row['codigo_articulo']  . '"' .  ",descri: " . $row['descripcion_articulo'] . ",precio: " . $row['precio_publico'] . ",stock: " . $row['stock_actual'];
  9. array_push($data, $name);
  10. }

  11. echo json_encode($data);