Databases Reference
In-Depth Information
// 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>";
// Show the gifts that are still unreserved
showgifts($connection, SHOW_UNRESERVED_GIFTS);
echo "\n<h3>Your Shopping List</h3>";
// Show the gifts that have been reserved by this user
showgifts($connection, SHOW_GIFTS_RESERVED_BY_THIS_USER);
?>
</body>
</html>
The showgifts( ) function is defined as:
// Show the user the gifts
//
// Parameters:
// (1) An open connection to the DBMS
// (2) Whether to show the available gifts or the current user's
// shopping list.
function showgifts($connection, $show_user_selection)
{
// Show the gifts...
}
and takes two arguments: an open connection to the MySQL server, and a value to
indicate whether to show available gifts (these can be added to the user's selection) or
the gifts reserved by this user (these can be removed from the user's selection). We
could use 0 and 1 for this indicator value. However, these values are not meaningful in
this context; does 0 mean we want to show reserved gifts or unreserved gifts? You might
 
Search WWH ::




Custom Search