Dynamically search SQL table and display on HTML using PHP and JavaScript
<p>I have a form where I want the user to select an Organization from a SQL table and when the form is submitted, the ID of the selected organization should be saved to a different table. I researched online and on SO, and this is what I have now. And it does not work. What's wrong? 
Newbrand.php:</p>

<pre><code>&lt;form action="newbrand.php" method="post"&gt;

        Brand Name: &lt;input type="text" name="bname" /&gt;&lt;br&gt;&lt;br&gt;
        Ogranization: &lt;input type="text" name="searchbar" id="searchbar"&gt;&lt;br&gt;&lt;br&gt;
        &lt;script&gt;
        $("#searchbar").keyup(function(){
        var searchTerm = $(this).val();

        $.post('search.php', { search_term: searchTerm}, function(data){

            $(".searchResults").html(data);
            $("#searchUl").css("display", "block");
            });
        });
        &lt;/script&gt;
        Organization ID: &lt;input type="hidden" name="gid" value="" /&gt;&lt;br&gt;&lt;br&gt;
        Gallery ID: &lt;input type="text" name="gid" /&gt;&lt;br&gt;&lt;br&gt;
&lt;/form&gt;
</code></pre>

<p>Search.php:</p>

<pre><code>&lt;?php
include 'db_connect.php';
$link = mysqli_connect($host, $username, $password, $db);

$search_term = sanitize(htmlentities($_POST['search_term']));

if (!empty($search_term)){

$search = "(SELECT `Organization_Name` FROM `organizations_info` WHERE `Organization_Name` LIKE '%$search_term%'  LIMIT 0, 5) ";
$query = mysqli_query($link, $search);
$result = mysqli_num_rows($query);

while ($row = mysqli_fetch_assoc($query)){
    #$user_id = $row['user_id'];
    #$username = $row['username'];
    $orgname = $row['Organization_Name'];
    $check = mysqli_num_rows($query);



    if ($check != 0){
        echo "&lt;a style='text-decoration: none; color: black;' href='newbrand.php?band=$orgname'&gt;&lt;li class='searchResults'&gt;" . ucfirst($orgname) . "&lt;/li&gt;&lt;/a&gt;";
    } else {
        echo "&lt;li class='searchResults'&gt;No Results Found&lt;/li&gt;";
    }
}
}
?&gt;
</code></pre>