I have a simple query that is suppose to take user inputted text and find words matching like a search engine. I use jquery’s post function to take this data and send it to a tags.php for processing. However, nothing is echoed out. I think my sql statement may be wrong. im pretty sure my database has keywords that match the input string.
PHP:
$tags=mysql_real_escape_string($_POST['tags']);
$query=mysql_query("SELECT * FROM tags WHERE tag LIKE '%$tags%'");
$num_rows=mysql_num_rows($query);
if ($num_rows == 0){
echo "<div class='result'>No Results</div>";
}
else{
while ($row=mysql_fetch_assoc($query)){
echo "<div>$row['tag']</div>";
}
}
JQUERY:
$('#tagsInput').keyup(function(){
var tags = $(this).val();
if (tags==''){
$('#tagResult').css("display" , "none");
}
else{
$('#tagResult').css("display" , "block");
$.post('../tags.php' , {tags: tags} , function(response){
$('#tagResult').html(response);
});
}
});
Copy and paste your while loop with this one :