Databases Reference
In-Depth Information
// (this also starts the session)
logincheck();
// 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.
// Define constants for use when calling showgifts
define("SHOW_UNRESERVED_GIFTS", 0);
define("SHOW_GIFTS_RESERVED_BY_THIS_USER", 1);
function showgifts($connection, $show_user_selection)
{
// See whether there are any gifts in the system
$query = "SELECT * FROM gifts";
// Run the query through the connection
if (($result = @ mysqli_query($connection, $query))==FALSE)
showerror($connection);
// Check whether any gifts were found
if (@ mysqli_num_rows($result) == 0)
// No; print a notice
echo "\n<h3><font color=\"red\">".
"There are no gifts described in the system!</font></h3>";
else
{
// Yes; display the gifts
// If we're showing the available gifts, then set up
// a query to show all unreserved gifts (where username IS NULL)
if ($show_user_selection == SHOW_UNRESERVED_GIFTS)
$query = "SELECT * FROM gifts WHERE username IS NULL ".
"ORDER BY description";
else
// Otherwise, set up a query to show all gifts reserved by
// this user
$query = "SELECT * FROM gifts WHERE username = '".
$_SESSION['username']."' ORDER BY description";
// Run the query through the connection
if (($result = @ mysqli_query($connection, $query))==FALSE)
showerror($connection);
// Did we get back any rows?
if (@ mysqli_num_rows($result) == 0)
{
// No data was returned from the query.
// Show an appropriate message
if ($show_user_selection == SHOW_UNRESERVED_GIFTS)
echo "\n<h3><font color=\"red\">No gifts left!</font></h3>";
else
 
Search WWH ::




Custom Search