Search into database based on user input : <p>I am a newbie in PHP. I am working on searching function, but it does not work well and I could not find why. The problem is; the <strong>$query has been sent and accepted well</strong> however it <strong>could not find the $query in the database</strong> even though the <strong>$query existed</strong>. I think, the <strong>$sql command might be wrong somewhere</strong>, but <strong>could not find it</strong> anyway. Thank you.</p>

<p>Here is my code: asset_search.php</p>

<pre><code>&lt;?php
//Search data in database
$query = $_GET['query'];
$min_length = 3;

if(strlen($query) &gt;= $min_length)
{
    //$query = htmlspecialchars($query);
    //$query = mysql_real_escape_string($query);
    $query = strtoupper($query);
    $sql = "SELECT * FROM asset WHERE ('asset_name' LIKE '%".$query."%')";
    $result = mysqli_query($conn, $sql);
    $row_cnt = mysqli_num_rows($result);

    $count = 0;

    if($row_cnt &gt; 0)
    {
        echo "&lt;table style='padding: 5px; font-size: 15px;'&gt;";
        echo "&lt;tr&gt;&lt;th style='width: 30px; border: 1px solid black; align:'center''&gt;No&lt;/th&gt;";
        echo "&lt;th style='width: 200px; border: 1px solid black; align:'center''&gt;Status&lt;/th&gt;";
        echo "&lt;th style='width: 200px; border: 1px solid black; align:'center''&gt;Asset Sub-identifier&lt;/th&gt;";
        echo "&lt;th style='width: 200px; border: 1px solid black; align:'center''&gt;Asset Name&lt;/th&gt;";
        echo "&lt;th style='width: 200px; border: 1px solid black; align:'center''&gt;Asset Type&lt;/th&gt;";
        echo "&lt;th style='width: 200px; border: 1px solid black; align:'center''&gt;Brand&lt;/th&gt;";
        echo "&lt;th style='width: 200px; border: 1px solid black; align:'center''&gt;Service Tag/ Product Tag/ Product S/N&lt;/th&gt;";
        echo "&lt;th style='width: 200px; border: 1px solid black; align:'center''&gt;CSM Tag&lt;/th&gt;";
        echo "&lt;th style='width: 200px; border: 1px solid black; align:'center''&gt;Action&lt;/th&gt;&lt;/tr&gt;";

        while($row = mysqli_fetch_assoc($result))
        {
             echo "&lt;tr&gt;&lt;td align='center'&gt;" . ++$count . "&lt;/td&gt;";
             echo "&lt;td align='center'&gt;" . $row["asset_status"] . "&lt;/td&gt;";
             echo "&lt;td align='center'&gt;&lt;a href='asset_viewfull.php?asset_id=" . $row["asset_id"] . "'&gt;&lt;ins&gt;" . $row["asset_subidentifier"] . "&lt;/a&gt;&lt;/ins&gt;&lt;/td&gt;";
             echo "&lt;td align='center'&gt;" . $row["asset_name"] . "&lt;/td&gt;";
             echo "&lt;td align='center'&gt;" . $row["asset_type"] . "&lt;/td&gt;";
             echo "&lt;td align='center'&gt;" . $row["asset_brand"] . "&lt;/td&gt;";
             echo "&lt;td align='center'&gt;" . $row["asset_sertag"] . "&lt;/td&gt;";
             echo "&lt;td align='center'&gt;" . $row["asset_csmtag"] . "&lt;/td&gt;";

             if($row["asset_status"] == "DISPOSE")
             {
                    echo "&lt;td align='center'&gt;&lt;a href='asset_delete.php?asset_id=" . $row["asset_id"] . "'&gt;Delete&lt;/a&gt;";
                    echo " ";
                    echo "&lt;a href='asset_print.php?asset_id=" . $row["asset_id"] . "'&gt;Print&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;";
             }else
             {
                    echo "&lt;td align='center'&gt;&lt;a href='asset_editform.php?asset_id=" . $row["asset_id"] . "'&gt;Edit&lt;/a&gt;";
                    echo " ";
                    echo "&lt;a href='asset_delete.php?asset_id=" . $row["asset_id"] . "'&gt;Delete&lt;/a&gt;";
                    echo " ";
                    echo "&lt;a href='asset_disposeform.php?asset_id=" . $row["asset_id"] . "'&gt;Dispose&lt;/a&gt;";   
                    echo " ";
                    echo "&lt;a href='asset_print.php?asset_id=" . $row["asset_id"] . "'&gt;Print&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;"; 
             }
        }

       }else
       {
          echo "&lt;tr&gt; There is no asset in the database &lt;/tr&gt;";
       }
       echo "&lt;/table&gt;";
}
else
{
    echo "&lt;script languange = 'Javascript'&gt;
            alert('Minimum length is' .$min_length);&lt;/script&gt;";
}

//Close connection
mysqli_close($conn);
$count = 0;
</code></pre>

<p>?></p>
