Simple if() not working as expected
I am sure that I am simply overlooking something, and I spent a few days working on this and cant seem to figure it out.

after logging in on the previous page I get the username and password,

    $username = mysql_escape_string($_POST['adminusername']);
    $password = mysql_escape_string($_POST['adminpassword']);

and then I go to the database to pull the username and password from the database,

    $sql = "SELECT username, password FROM `weaponsadmin`";
    $rows = $db->query($sql); while ($record = $db->fetch_array($rows)) {

now here is the part that is confusing me, if i have the following, no matter what I use for the username or password, it will NOT allow for me to login,

    if ( ($record[username]==$username) && ($record[password]==$adminpassword) ){
    $_SESSION['loggedin'] = true;
    $_SESSION['username'] = $adminusername;
    header( "Location: admin.php" ) ;
    } else { header( "Location: index.php?login=error" ) ;
    }

however if I use the following, it will allow me to login in if the username is correct, but it allows for me to input anything for password and it works,

    $adminusername = $record[username]; 
    $adminpassword = $record[password];

    if ( ($adminusername==$username) && ($adminpassword==$adminpassword) ){
    $_SESSION['loggedin'] = true;
    $_SESSION['username'] = $adminusername;
    header( "Location: admin.php" ) ;
    } else { header( "Location: index.php?login=error" ) ;
    }

So in summary for some reason the `&&` part doesn't seem to work correctly and if somebody could help me with the code and let me know where my code could be improved for better security and how to make this work correctly, thanks 
Simple if() not working as expected
===

I am sure that I am simply overlooking something, and I spent a few days working on this and cant seem to figure it out.

after logging in on the previous page I get the username and password,

    $username = mysql_escape_string($_POST['adminusername']);
    $password = mysql_escape_string($_POST['adminpassword']);

and then I go to the database to pull the username and password from the database,

    $sql = "SELECT username, password FROM `weaponsadmin`";
    $rows = $db->query($sql); while ($record = $db->fetch_array($rows)) {

now here is the part that is confusing me, if i have the following, no matter what I use for the username or password, it will NOT allow for me to login,

    if ( ($record[username]==$username) && ($record[password]==$adminpassword) ){
    $_SESSION['loggedin'] = true;
    $_SESSION['username'] = $adminusername;
    header( "Location: admin.php" ) ;
    } else { header( "Location: index.php?login=error" ) ;
    }

however if I use the following, it will allow me to login in if the username is correct, but it allows for me to input anything for password and it works,

    $adminusername = $record[username]; 
    $adminpassword = $record[password];

    if ( ($adminusername==$username) && ($adminpassword==$adminpassword) ){
    $_SESSION['loggedin'] = true;
    $_SESSION['username'] = $adminusername;
    header( "Location: admin.php" ) ;
    } else { header( "Location: index.php?login=error" ) ;
    }

So in summary for some reason the `&&` part doesn't seem to work correctly and if somebody could help me with the code and let me know where my code could be improved for better security and how to make this work correctly, thanks 