First of all...please correct the following statements
$_POST['username'] = $username;
$_POST['password'] = $password;
$username = $_POST['username'];
$password = $_POST['password'] ;
Second...if you haven't stored user's passwords in the database encrypted in md5...it won't work.
So...I would advise to you get the script working without using md5 first...
once you have...go back and implement md5 in your script.