PHP login, advise needed!

I recently purchase a book on PHP & mySQL, and needed to build a php & mysql based system, however, as i went along and did all the code, i kept getting errors, untill i started to modify it and have got it to work, however, i wanted to ask you expert PHP heads here, for your advise on my new code and the books original code, just a reassurance if you can.

----book code (DOES NOT WORK)----


<?
if ((!$_POST[username]) || (!$_POST[password])) {
   header( "Location: http://127.0.0.1/show_login.html");
   exit;
}
$db_name = "testDB";
$table_name = "auth_users";
$connection = @mysql_connect("localhost", "spike", "9sj7En4")
or die(mysql_error());
$db = @mysql_select_db($db_name, $connection) ©Ú
die(mysql_error());
$sql = "SELECT * FROM $table_name WHERE username =
'$_POST[username]' AND password = password('$_POST[password]')";

$result = @mysql_query($sql,$connection) or die(mysql_error());
$num = mysql_num_rows($result);
if ($num != 0) {
   $msg = "<P>Congratulations, you're authorized!</p>";
} else {
   header("Location: http://127.0.0.1/show_login.html");
   exit;
}
?>
<HTML>
<HEAD>
<TITLE>Secret Area</TITLE>
</HEAD>
<BODY>
<? echo "$msg"; ?>
</BODY>
</HTML>

—my code (THIS WORKS)—


<?
if ((!$_POST[username]) || (!$_POST[password])) {
   header( "Location: login.html");
   exit;
}
$connection = @mysql_connect("localhost", "***", "*****")
or die(mysql_error());
$db = @mysql_select_db("dbme", $connection) or die(mysql_error());
$sql = "SELECT id FROM user WHERE name =
'$_POST[user]' AND password = '$_POST[password]'";

$result = @mysql_query($sql,$connection) or die(mysql_error());
$num = mysql_num_rows($result);
if ($num != 1) {
   $msg = "<P>Congratulations, you're authorized!</p>";
} else {
   header("Location: login.html");
   exit;
}
?>
<HTML>
<HEAD>
<TITLE>Secret Area</TITLE>
</HEAD>
<BODY>
<? echo "$msg"; ?>
</BODY>
</HTML>