Listing Gifts for Selection

After logging in to the application, users are sent to the list.php page that displays all the gifts that are still available (not yet reserved by a wedding guest). The page also displays the gifts that the user has already reserved.

As with the gift editing page, we create the outline of an HTML page and call on a custom function—in this case, the function showgifts()—to read the gift information from the database and generate the required HTML:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Jack and Jill's Wedding Gift Registry</title> </head> <body bgcolor='LIGHTBLUE'> <?php // Show a logout link echo "<a href='logout.php'>Logout</a>"; // Check whether the user is Jack or Jill (username is 'jack' or // 'jill'); if so, show a link to the gift editing page. if($_SESSION['username']=="jack" || $_SESSION['username']=="jill") echo " | <a href='edit.php'>Edit gifts</a>"; // Connect to the MySQL DBMS and use the wedding database - // credentials are in the file db.php if(!($connection= @ mysqli_connect( $DB_hostname, $DB_username, $DB_password, $DB_databasename))) showerror($connection); // Pre-process the message data for security if(count($_GET)) $message = clean($_GET["message"], 128); // If there's a message to show, output it if (!empty($message)) echo "\n<h3><font color=\"red\"><em>". urldecode($message)."</em></font></h3>"; echo "\n<h3>Here are some gift suggestions</h3>"; // ...

Get Learning MySQL now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.