Try this:
Click on the server tab in Mamp.
click on the select MySQL root password. create one; for the example I'll call it "password",
then, your php code must start like this:
<?php
mysql_connect("localhost", "root", "password");
mysql_select_db("your_database");
/*
php code...