Jason and Pete offer some good suggestion. But it would help if we had a better understanding of your problem. You state that the code displays the output of your echo statement, but you do not tell us if any errors are getting displayed (this would be helpful to know if there are any). Then you state a connection is not getting made.
If it is true that the connection is not made, then the point where your code fails first is on the mysql_connect statement. In order to verify this, you should modify your connect statement to handle the connection error. So the statement should be written like so:
$conn = mysql_connect ("localhost","root","password") or die("Could not connect to db.");
If you see the "Could not connect to db" message after modifying the connect statement and executing your code, then you definitely are not connecting to MySQL. Assuming the user credentials are correct for a localhost connection, the first thing I would check is to see if PHP is configured to talk to MySQL. You can do this by creating a page that contains the statement:
phpinfo();
?>
Executing the above statement will display your PHP configuration information. Search for a section titled mysql. If you can't find this section, then PHP does not have the necessary extension to talk to MySQL. So you will have to locate your php.ini file (usually found in the php directory) and add the following to the end of the file:
[PHP_MYSQL]
extension=php_mysql.dll
This assumes PHP is installed on a Windows machine, that the extension_dir is set, and php_mysql.dll resides in the extension directory. Once you have made the changes you must restart your web server for the changes to take affect (just restart your computer if you don't know how to restart the web server).
The missing extension is a common mistake for new users who have installed PHP and MySQL for the first time. If none of the suggestions work, contact me and I will try to help you get your code working.