<?php
page_header
('This is a test');

require_once(
'templates/layout.php');
page_header('Show bookmarks');
?>
<h1>List my bookmarks</h1>
<?php
//Have we got a user ID specified?
if (is_numeric(@$_GET['id'])) {
    
$uid $_GET['id'];
} else {
    exit(
'User ID not specified');
}

//Include constants file; this file simply defines two constants,
//DB_USERNAME and DB_PASSWORD. We haven't written them here for
//obvious reasons :-)
require_once('/home/uchiyama/public_html/includes/constants.php');

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

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

//Executes the query (selects all columns and rows from the addresbook table)
$result mysql_query('SELECT bookmark_url from addressbook, bookmarks WHERE id = '.$uid
.' AND bookmark_uid = id');

if (
mysql_num_rows($result) == 0) {
    echo 
'<p>No bookmarks!</p>';
} else {
    echo 
'<ul>';
    
    
//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 
"<li>{$row['bookmark_url']}</li>";
    }
    
    echo 
'</ul>';
}

page_footer();