Auto complete not showing certain usernames

Basically, i am trynna make an autocomplete for usernames, it works when i enter my name "cool"

But whenever i enter my friends name that is also in the db named "vanilla" it doesn’t come up?

My HTML code:

<!DOCTYPE html>
<html lang="en-US">
<meta charset="utf-8">
    padding: 20px;
    height: 25px;
    font-size: 16px;

<link rel="stylesheet" href="//">
  <link rel="stylesheet" href="/resources/demos/style.css">
  <script src=""></script>
  <script src=""></script>
<!-- Initialize autocomplete -->
  $( function() {
    $( "#tags" ).autocomplete({
      source: 'search.php'
  } );
<div class="container"> 
        <div class="ui-widget">
  <label for="tags">Tags: </label>
  <input id="tags">


// Database configuration
$dbHost     = "localhost"; 
$dbUsername = "username"; 
$dbPassword = "password"; 
$dbName     = "database"; 

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

// Check connection
if ($db->connect_error) {
    die("Connection failed: " . $db->connect_error);

// Get search term
$searchTerm = $_GET['term'];

// Fetch matched data from the database
$query = $db->query("SELECT username FROM users WHERE username LIKE '%".$searchTerm."%'");

// Generate array with skills data
$skillData = array();
if($query->num_rows > 0){
    while($row = $query->fetch_assoc()){
        $data['id'] = $row['id'];
        $data['value'] = $row['username'];
        array_push($skillData, $data);

// Return results as json encoded array
echo json_encode($skillData);

I’ve looked around on google a little but it all gives the same answers and it doesn’t actually show my other users… except than only a selected few which is very strange.

So if anyone can point out the issue i’ll be forever greatful.


102 thoughts on “Auto complete not showing certain usernames”

Leave a Comment