confused - why am i getting this message?



hi, i have started making a script and this is the code so far...

require ("dblink.php");

if ($username && $password){

$Query = "SELECT * FROM users WHERE username='$username' AND password='$password'";
$Result = mysql_db_query($DBName, $query, $link);

$validated = 0;
while ($Rowlogin = mysql_fetch_array($Result)){
$validated = 1;

echo "You have been redirected to this page from the wrong place, or your username and/or password was left blank. Please <a href=\"../login.htm\">Login</a>";


the trouble is when i try to run it i get the following message..

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/gav/public_html/secure/login.php on line 12

surely someone can tell me why im getting this message? if so thanks