I keeep getting this error: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\Projeto\search.php on line 7

How do I fix?

if (isset($_POST['action']) == 'Search') {
    $search = $_POST['search'];

    require 'conf/connection.php';

    $selection = mysql_query("SELECT * FROM users WHERE name '%$search%'");
    $number = mysql_num_rows(mysql_query("SELECT * FROM users WHERE name '%$search%'"));
}
Member Avatar for diafol
$r = mysql_query("SELECT * FROM users WHERE name '%$search%'");
$number = mysql_num_rows($r);

You need to clean the input:

$search = mysql_real_escape_string($_POST['search']);

but this needs to come after the connection or you'll get an error.

Oh now i see, thanks very much!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.