Please do use the brand new password hash API in PHP 5.5. If you are on an older version, use https://github.com/ircmaxell/password_compat to get the same functions in PHP as old as version 5.3.7.
Usage is very simple:
When creating the account:
$hash = password_hash($password);
Store the hash in the database.
Verification:
if (password_verify($posted_password, $hash_from_db)) { // login }
See the documentation for more info!
Note that you have to read the hashed password from the database to get the salt it had used. That is also the error in your code. You cannot create a random salted hash when you are comparing the login password with the original hash. You have to compare the two hashes, and the login password has to be hashed with the same salt as the original password. Otherwise the hashes won't match.