First of all, try to avoid using front ends such as DreamWeaver: they make the code a mess and are very hard to maintain. Write your code using notepad and you will feel much better.
Secondly, when connecting to db:
function dbconnect()
{
$link = mysql_connect("localhost", "username", "pwd") or die(" Could not connect : " . mysql_error());
mysql_select_db("table_name") or die("Could not select database");
return($link);
}
(you need $link to close the database later).
Use (" Could not connect : " . mysql_error()); in your calls, so you will KNOW why you failed.
Finally, error 401 Unauthorised is classic: you have not set the correct permissions on the file/directory.
If you use CPANEL (most common), go there, move to the directory you want. Check the permissions. 777 is allow everything... (dangerous!).
Good luck.