搜索关键字并在未找到结果时抛出“未找到”错误

I want to search a keyword with the use of the MySQL's LIKE clause (for example: LIKE %$keyword%) and then get the result back. If there are no results, i want to show some error message.

I have a table named ads_post and i'm searching for the keyword in the fields named cat_name and city_name.

Could someone help me with this?


search-result.php

<?php 
    if (isset($_GET['submit'])) {
        $keyword = $_GET['keywoed'];
        $query = "select * from ads_post where cat_name like '%$keywoed%' or city_name like '%$keywoed%'";
        $result = mysqli_query($conn, $sql);

        if (mysqli_num_rows($result) > 0) {
            while ($row = mysqli_fetch_assoc($result)) {
                echo "cat Name: " . $row["cat_name"] . "<br>";
            }
        } else {
            echo "0 results";
        }

        mysqli_close($conn);
    } 
?>

HTML form code

<form action="search-result.php" method="get" >
    <input class="form-control"  name="keyword" placeholder="Search any keyword..?">
    <input type="submit"   value="search">
</form>

i catch something

$query = "select * from ads_post where cat_name like '%$keywoed%' or city_name like '%$keywoed%'";
        $result = mysqli_query($conn, $sql);

first defined $query but mysqli_query is $sql please replace $query not $sql :)

$result = mysqli_query($conn, $query);

you can replace

$query = "select * from ads_post where cat_name like '%$keywoed%' or city_name like '%$keywoed%'";

with

   $query = "select * from ads_post where cat_name like '%$keyword%' or city_name like '%$keyword%'";

and other

$keyword = $_GET['keywoed'];

with replace

$keyword = $_GET['keyword'];