Pseudocode:
$q=$db->prepare('SELECT * FROM usertable WHERE username=? AND passwordhash=?');
$thehashvalue=calc_hash_of_password_according_to_your_agorithm($params);
$theusername=the_username_that_was_posted();
$q->execute(array($theusername, $thehashvalue));
$lastlogin=null;
while($r=$q->fetch(PDO::FETCH_ASSOC)) {
# successfully authenticated
$lastlogin=$r['lastlogin']; ## example. assumes a "lastlogin" column on "usertable"
}
if(!empty($lastlogin)) {
# user is logged in
}else{
# login failed
}
The hash calc function could be as simple as md5($posted_passwd)
but it is good practise to salt the hash so the same password makes different hashes for different users and/or on different systems. Just make sure you use the same hash function when storing the password hash in the database.