Hi All,
I am trying to create some search functionaltiy for my website, but for some reason when I search any word, even if its not in my database it will display all the results from a particular column.
Here is my code
<?php
error_reporting( ~E_DEPRECATED & ~E_NOTICE );
define('DBHOST', 'localhost');
define('DBUSER', 'root');
define('DBPASS', 'mypass123');
define('DBNAME', 'topgrub');
$conn = mysqli_connect(DBHOST,DBUSER,DBPASS);
$dbcon = mysqli_select_db($conn,DBNAME);
if ( !$conn ) {
die("Connection failed : " . mysqli_error());
}
if ( !$dbcon ) {
die("Database Connection failed : " . mysqli_error());
}
?>
<?php
if(isset($_POST['search'])){
$q = $_POST['q'];
$query = mysqli_query($conn,"SELECT * FROM `products` WHERE `name` LIKE '%$qname%'");
$count = mysqli_num_rows($query);
if($count == "0"){
$output = '<h2>No result found!</h2>';
}else{
while($row = mysqli_fetch_array($query)){
$s = $row['name'];
$output .= '<h2>'.$s.'</h2><br>';
}
}
}
?>
Any ideas wheer I have gone wrong?
Thanks