<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
    <title>My address book</title>
</head>
<body>
<h1>List my contacts</h1>
<?php
//Include constants file; this file simply defines two constants,
//DB_USERNAME and DB_PASSWORD.
require_once('constants.php');

//Connects to the database server
$sql mysql_connect('localhost'DB_USERNAMEDB_PASSWORD);
if (!
$sql) {
    exit(
'Connection failed');
}

//Selects the appropriate database (uchiyama_test is the name of our database)
if (!mysql_select_db('uchiyama_test')) {
    exit(
'Database selection failed');
}

//Executes the query (selects all columns and rows from the addresbook table)
$result mysql_query('SELECT * from addressbook');

echo 
'<table border="1">
<tr><th>ID</th><th>Name</th><th>State</th><th>Phone number</th></tr>'
;

//Repeats the fetch-next-row process until the end of all the rows is reached
//$row becomes an associative array representing one row, with the column names as keys
while ($row mysql_fetch_assoc($result)) {
    echo 
"<tr>
            <td>{$row['id']}</td>
            <td>{$row['first_name']} {$row['last_name']}</td>
            <td>{$row['state']}</td>
            <td>{$row['phone']}</td>
    </tr>"
;
}

echo 
'</table>';

?>
<hr />
<div><a href="newcontact.php">Add new contact</a></div>
</body>
</html>