mysql_fetch_array () / mysql_fetch_assoc () / mysql_fetch_row () / mysql_num_rows etc… espera que o parâmetro 1 seja um recurso ou resultado

Eu estou tentando selecionar dados de uma tabela MySQL, mas recebo uma das seguintes mensagens de erro:

mysql_fetch_array () espera que o parâmetro 1 seja um recurso, booleano dado

ou

mysqli_fetch_array () espera que o parâmetro 1 seja mysqli_result, booleano dado

ou

Chamar para uma função de membro fetch_array () em boolean / non-object

Este é o meu código:

$username = $_POST['username'];
$password = $_POST['password'];

$result = mysql_query('SELECT * FROM Users WHERE UserName LIKE $username');

while($row = mysql_fetch_array($result)) {
    echo $row['FirstName'];
}

O mesmo se aplica ao código como

$result = mysqli_query($mysqli, 'SELECT ...');
// mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given
while( $row=mysqli_fetch_array($result) ) {
    ...

e

$result = $mysqli->query($mysqli, 'SELECT ...');
// Call to a member function fetch_assoc() on a non-object
while( $row=$result->fetch_assoc($result) ) {
    ...

e

$result = $pdo->query('SELECT ...', PDO::FETCH_ASSOC);
// Invalid argument supplied for foreach()
foreach( $result as $row ) {
    ...

e

$stmt = $mysqli->prepare('SELECT ...');
// Call to a member function bind_param() on a non-object
$stmt->bind_param(...);

e

$stmt = $pdo->prepare('SELECT ...');
// Call to a member function bindParam() on a non-object
$stmt->bindParam(...);

questionAnswers(30)

yourAnswerToTheQuestion