SEARCH function using MySQL & PHP

This code is all you will need to build a simple SEARCH function using MySQL & PHP.


<form method="post">
        <input type="text" name="inp_search" id="inp_search" autocomplete="off">
        <button type="submit" name="btn_search">Search</button>
    </form>

<table>
    <tr>
        <th>#</th>
        <th>First name</th>
        <th>Last name</th>
        <th>Age</th>
    </tr>

<?php

    $conn = mysqli_connect('localhost', 'root', '', 'crud-app');

    if (!$conn) {

        die ("No connection" . mysqli_connect_error($conn));
    }

    if (isset($_POST['btn_search'])) {

        $search = $_POST['inp_search'];

        $query = "SELECT * FROM `crud-app-tbl` WHERE id='$search' or 
        first_name LIKE '%$search%' or last_name LIKE '%$search%'";

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

        if (mysqli_num_rows($result) > 0) {

            while ($row = mysqli_fetch_assoc($result)) {
                echo '<tr>
                        <td><a href="#">' . $row['id'] . '</a></td>
                        <td>' . $row['first_name'] . '</td>
                        <td>' . $row['last_name'] . '</td>
                        <td>' . $row['age'] . '</td>
                        </tr>';
            }

        } else {

            echo 'No data!';
        }
    
    } else {

        echo 'Start your SEARCH here!';

    }

    ?>

    </table>