I've always found the simplest way to connect to the database and run queries is in two parts:
<?php
$dbhost = 'localhost';
$dbname = 'my_database';
$dbuser = 'root';
$dbpasswd = '';
// access MySQL
$dbc = mysql_connect ($dbhost, $dbuser, $dbpasswd);
// access the database
mysql_select_db ($dbname);
?>
Stick that bit in a separate file (connect.php) which you include in every page with an
include "connect.php";
statement. The next bit is for running any query:
$query = "SELECT * FROM `tablename` WHERE `some_column`=10";
$result = mysql_query($query);
Then after that you can grab the data out of the $result resource however you like.