You're using second parameter in your crypt()
call, so it's treated as salt. To compare properly, you can use:
if ($password == crypt($mypassword))
{
echo "Success! Valid password";
}
But PHP provides native functionality for hashing routines - it is introduced if 5.5 version and called password hashing.
For PHP versions below 5.5 down to 5.3.7, there is a backported compatibility function that does the same: https://github.com/ircmaxell/password_compat Just include it and use it.
But note that you have to read the hashed password from the database and then compare it with PHP. You cannot query the database with a newly created password hash to find the user.