I have made a php search bar before, which worked fine. However, I have recently been developing a one-file web app using the jQuery mobile framework. The aim is to be able to search for a certain trade, person or business, but the results are not showing up. If you search, and there are no results, the message in the output variable prints "There are no results" on the page. The code for the search bar is below:
if(isset($_POST['search'])){
$searchq = $_POST['search'];
$searchq = preg_replace("#[^0-9a-z]#i", "", "$searchq");
$squery = mysql_query("SELECT * FROM users WHERE name LIKE '%$searchq%' OR fname LIKE '%$searchq%' OR lname LIKE '%$searchq%' OR trade LIKE '%$searchq%' LIMIT 10") or die("Could not search");
$counts = mysql_num_rows($squery);
$output = '';
$outputs = '';
if($counts != 0){
while($row = mysql_fetch_array($searchq)){
$ids = $row['id'];
$fnames = $row['fname'];
$lnames = $row['lname'];
$trades = $row['trade'];
$abouts = $row['about'];
$emails = $row['email'];
$numbers = $row['number'];
$names = $row['name'];
$output .= '<div>'.$trades.' '.$ids.'</div>';
}
}else{
$output = 'Sorry there were no results';
}
}
I print this to the page with:
<h1><?php print($output); ?></h1>
It may also be worth noting that the first feature using php (the sign up form) worked perfectly, but the login form on the same page didn't, and neither does the search bar; I am wondering if having different forms on the same page accessing the same database may cause some kind of problem. If anyone requires any more code, just leave a comment. Thank you in advance.