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

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!