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%'"));
}

Recommended Answers

$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.

Jump to Post

All 2 Replies

Member Avatar
$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 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.