I didn't test it to see if it works, but here goes (just replace table names and other stuff with the ones you have).
<?php
//Allowing session vars
session_start();
//Connecting to a MySQL DB
$connection = @ mysql_connect('host', 'user', 'pass') or die('Error: cannot connect database.');
mysql_select_db('dbname', $connection);
//Retrieving the value typed on a form textbox (I'm assuming there was a form on the previous page, with a "password" field)
$typed_password = '';
if (isset($_POST['txtPassword'])) $typed_password = trim($_POST['txtPassword']);
//Hash the data retrieved from the form field, to compare with the hashed value in the DB table field.
//Note that I didn't salt this one, that's gonna be up to you, if the one recorded on the table is salted.
$hashed_password = hash('md5', $typed_password);
//Querying for the user name, comparing the typed password with the one on the BD
$sql = 'SELECT theTable.theName FROM theTable WHERE (theTable.thePassword="' . $hashed_password . '");';
$success = @ mysql_query($sql) or die('Error retrieving data.');
if (mysql_num_rows($success) > 0) {
//Success! Get the user name, and...
$userdata = mysql_fetch_array($success);
//... create all necessary session vars.
//You can use this one to check every page if you are still logged in
$_SESSION['loggedin'] = 'yes';
//And this one, just for display purposes
$_SESSION['username'] = $userdata['name'];
//Just for display
echo 'Welcome back, ' . $_SESSION['username'] . '.';
}
else {
//Password didn't match.
echo 'Wrong password.';
}
//Closing query and connection to DB
mysql_free_result($success);
mysql_close($connection);
?>