w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Input validation on search (Showing "no search result" on empty input)

change this

    $searchq = $_POST['search'];

    to this

        $searchq =trim(strip_tags( $_POST['search']));  
$query = mysql_query("SELECT * FROM user WHERE initial LIKE '%$searchq%' OR
lname    LIKE '%$searchq%'") or die ("could not search");
$count = mysql_num_rows($query);

    // you can also use empty($searchq)
        if(!strlen($searchq) >0 || $count==FALSE)
        print whatever you want to print here

and please stop using mysql_query

It was deprecated before it was deprecated.

© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.