I am trying to filter out data from my table using a searchbox in HTML. My search box which should return value from SQL query.
But even if I search, the filtered table is not displayed.
I have checked the 'LIKE' query in phpMyAdmin with '%n' (which I meant an entry in my table ending with 'n' ) and it works, but since in mine I am searching for a specific text that is entered in the search box, I couldn't check for the query that I am using.
Would really appreciate any help and thanks in advance.
<?php
//error_reporting(E_ERROR | E_PARSE);
$db_host = 'localhost';
$db_user = 'zamil'; // Username
$db_pass = '1234'; // Password
$db_name = 'resi'; // Database Name
$conn = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
if (!$conn) {
die ('Failed to connect to MySQL: ' . mysqli_connect_error());
}
else{
print("connected");
}
$output = '';
$query = '';
if (isset($_GET['search'])){
$searchq = $_GET['search'];
$searchq = preg_replace("#[^0-9a-z]#i","",$searchq);
$query = mysqli_query( $conn, "SELECT * FROM 'salesflow' WHERE 'Rep Name'
LIKE '%$searchq%'") or die("could not search!");
$count = mysqli_num_rows($query);
if($count == 0){
$output = 'There was no entries';
}else{
while ($row = mysqli_fetch_array($query)) {
$cname = $row['Source of Content'];
$rname = $row['Rep Name'];
$output .= '<div>'.cname.' '.rname.'</div>';
}
}
}
if ($query != 0) {
die ('SQL Error: ' . mysqli_error($conn));
}
?>
<form action="Sales1.php" method="post">
Search: <input type="text" name="search" />
<input type="submit" value="Search" /><br />
</form>
<?php print("$output"); ?>
</body>
</html>