I am fairly new to PHP and i have a problem

. When I login, it redirects me to the desired page. but when the password is incorrect, it still redirects to the same page.
PHP Code:
<?
session_start();
$user = $_POST["username"];
$pass = md5($_POST["password"]);
$host = "localhost";
$dbuser = "rsf_dredd";
$dbase = "rsfdredd_uk_db";
mysql_connect($host,$dbuser);
mysql_select_db($dbase);
$sql = mysql_query("SELECT * FROM cms WHERE user=$user and password=$pass");
$num = mysql_num_rows($sql);
if ($num = 1) {
header("Location:admin_index.php");
} else {
$_SESSION["error"] = "<font color=red>Wrong username or passowrd. Try again.</font>";
header("Location:admin.php");
}
?>