I’ve created an ajax search box using the keyup function to find profiles in my database.
$('#asearch').keyup(function(){
var search_term = $(this).val();
The problem I’m having is that in my search box once I hit the space bar after typing the first name my page is no longer populated with results. Looking to make it so I can search a first name enter a space and a last name and still have results.
if (isset($_POST['search_term'])){
$search_term = mysql_real_escape_string(htmlentities($_POST['search_term']));
if (!empty($search_term)){
$search = mysql_query("SELECT `firstname`, `lastname` FROM `tempusers`
WHERE `firstname` LIKE '%$search_term%'");
$result_count = mysql_num_rows($search);
while ($results_row = mysql_fetch_assoc($search)) {
echo '<li>', $results_row['firstname'],' ', $results_row['lastname'], '</li></br>';
}
}
}
Tried using a regex $search_term = preg_split('/[\s]+/', $search_term); but it did not work like I was hoping it would. Any tips one may have will be greatly appreciated
Use the trim() function:
Plugging it into your code:
By the way, is there a reason that you are using htmlentities on input?