Secure pass word in database

What would be the best way to go about securing passwords in database, I know MD5 is no longer safe and very easy to crack. any tips and advice on how to improve my register code?

	function register(){
		#checking if username, password, firstname, lastname are set.
			if(isset($_POST['username'], $_POST['password'], $_POST['firstname'], $_POST['lastname'])){

				#selecting data from `users`.
				$query = dbConnect()->prepare('INSERT INTO `users`(username, password, firstname, lastname) VALUES(:username, :password, :firstname, :lastname)');
				
				#binding values
				#username fields
				$query->bindValue(':username', $_POST['username']);
				if(empty($_POST['username'])){
					echo 'Please enter a username';
				}

				#password not yet secured.
				$query->bindValue(':password', $_POST['password']);
				if(empty($_POST['password'])){
					echo 'Please enter a password';
				}

				#firstname
				$query->bindValue(':firstname', $_POST['firstname']);
				if(empty($_POST['first name'])){
					echo 'Please enter a first name';
				}

				#lastname
				$query->bindValue(':lastname', $_POST['lastname']);
				if(empty($_POST['lastname'])){
					echo 'Please enter a last name';
				}
				else{

				#if all fields above are good, then execute!
				if($query->execute()){
					header('Location: login.php');
				}
			}
		}
	}

Use a different hashing algorithm to replace MD5. Also make sure the password is SALTed.

http://www.php.net/manual/en/function.hash.php
http://www.php.net/manual/en/function.hash-algos.php

http://www.php.net/manual/en/faq.passwords.php

These days, the password hashing functions are your best bet. They were introduced in PHP v5.5. Or if you’re on PHP v5.3.7+, then you can use this [URL=“https://github.com/ircmaxell/password_compat”]forward compatibility library.