I have this ajax request where i try to find some tags and add it to search results
The problems comes when i try with my php script to find something then it doesn't find anything
<div>
<form action="search()" method="post">
    <label for="tagsearch">Search tags: </label>
    <input type="text" id="tagSearch" name="tagsearch"/>
    <input type="button" id="tagenter" value="Add tag"/>
</div>
<div id="tagHolder">
    <!--Tags here-->
</div>
</div>
<script type="text/javascript">
    $(document).ready(function(){
        function search(){
            var tag=$("tagSearch").val();
            if(tag!=""){
                $("#tagHolder").html();
                $.ajax({
                   type:"post",
                    url:"gettag.php",
                    data:"tag="+encodeURIComponent(tag),
                    success:function(data){
                        $("#tagHolder").html(data);
                        $("#tagSearch").val("");
                    }
                });
            }
        }
        $("#tagenter").click(function(){
            search();
        });
        $('#tagSearch').keyup(function(e){
            if(e.keyCode == 13){
                search();
            }
        });
    });
</script>
The above code is the ajax request.
This is the php script
//Connect to database
$con = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
//Check if connection is up
if(mysqli_connect_errno()){
    echo "Couldn't connect". mysqli_connect_error($con);
}
$tag = $_POST["tag"];
$result=mysqli_query($con, "SELECT * FROM tags WHERE tag = '".$tag."'");
$found=mysqli_num_rows($result);
if($found>0){
    while($row=mysqli_fetch_array($result)){
        echo "<div>". $row['tag'] . "</div>";
    }
}else{
    echo "<div>No suggestions</div>";
}
mysqli_close($con);
Im getting the "No suggestions" as search result. My guess is that the SQL query is wrong or the $found variable is wrong.

 
     
    