[Solved] Error in PHP Search [duplicate]


You should check if $_POST[‘searchterm’] is set first. It will only be set when the form is submitted.

Also don’t use Mysql_ functions. They are deprecated. Would advice you to use MySQLI since they have protection against SQL Injection attacks etc.

if(isset($_POST['searchterm']))
{
    $search = mysql_real_escape_string($_POST['searchterm']);

    $find_books = mysql_query("SELECT * FROM `listings` WHERE `title` LIKE '%$search%'");

    if(mysql_num_rows($find_books) > 0)
    {
        while($row = mysql_fetch_assoc($find_books))
        {
            $title = $row['title']; 
            echo "$title<br />";
        }
    }
    else
    {
        echo "No Record found";
    }
}

6

solved Error in PHP Search [duplicate]