Here is my scenario, All things were working fine ,based on what I enter in the search form the appropriate image was displayed. But since I have added that auto suggest feature on my site, it seems like whatever I write in search box and presses search, I think my input form is not sending data to php. beacuse even if I type something in form, Still this condition is getting false.
( $name contains the value user inputs):
if(!empty($name))
Here is my html form:
<form class="searchform" action="webpage.php" method="POST">
<input class="searchfield autosuggest" type="text" placeholder="Search for a name " onFocus="if (this.value == 'Search...') {this.value = '';}" onBlur="if (this.value == '') {this.value = 'Search...';}" />
<input class="searchbutton" type="submit" value="Go" />
</form>
The latest script I added for auto suggest is this :
//Autosuggest starts here
$(document).ready(function(){
$('.autosuggest').keyup(function(){
var search_term= $(this).attr('value');
$.post('search.php',{search_term:search_term},function(data){
$('.results').html(data);
$('.results li').click(function(){
var result_value = $(this).text();
$('.autosuggest').attr('value',result_value);
$('.results').html('');
});
});
});
});
</script>
Finally this is another search.php file for querying through the database for autosuggest :
if(isset($_POST['search_term'])== true && empty($_POST['search_term'])== false)
{
$search_term = mysql_real_escape_string($_POST['search_term']);
$query = mysql_query("select * from user_info where Name LIKE '$search_term%'");
while(($rows = mysql_fetch_assoc($query))!== false)
{
echo '<li>'.$rows['Name'].'</li>';
}
}
Now the auto suggest is working but not the main site. Could it be a positioning issue of my image or php not receiving data from my input form ?
you should add name attribute to your input box