Specifications
This function is fairly simple. It checks that a user does not already have this bookmark listed
in the database. (Although it is unlikely that they would enter a bookmark twice, it is possible
and even likely that they might refresh the page.) If the bookmark is new, then it is entered into
the database.
Looking back at add_bm.php, you can see that the last thing it does is call get_user_urls()
and display_user_urls(), the same as member.php. We’ll move on and look at these func-
tions next.
Displaying Bookmarks
In the member.php script and the add_bm() function, we used the functions get_user_urls()
and display_user_urls(). These functions get the user’s bookmarks from the database and
display them, respectively. The
get_user_urls() function is in the url_fns.php library, and the
display_user_urls() function is in the output_fns.php library.
The get_user_urls() function is shown in Listing 24.23.
LISTING 24.23 The get_user_urls() Function from url_fns.php—This Function Retrieves a
User’s Bookmarks from the Database
function get_user_urls($username)
{
// extract from the database all the URLs this user has stored
if (!($conn = db_connect()))
return false;
$result = mysql_query( “select bm_URL
from bookmark
where username = ‘$username’”);
if (!$result)
return false;
//create an array of the URLs
$url_array = array();
for ($count = 1; $row = mysql_fetch_row ($result); ++$count)
{
$url_array[$count] = $row[0];
}
return $url_array;
};
Let’s briefly step through this function. It takes a username as parameter, and retrieves the
bookmarks for that user from the database. It will return an array of these URLs or false if the
bookmarks could not be retrieved.
Building User Authentication and Personalization
C
HAPTER 24
24
AUTHENTICATION
AND
PERSONALIZATION
529
30 7842 ch24 3/6/01 3:34 PM Page 529










