Databases Reference
In-Depth Information
Figure 15-4. The wedding registry list page showing reserved gifts
// The user wants to add a new item to their shopping list.
...
}
else // The action is not add, so it must be remove
{
// The user wants to remove an existing item from their shopping list.
}
// Redirect the browser back to list.php
header("Location: list.php?message=" . urlencode($message));
exit;
At the end of the script, after adding or removing the gift, we redirect the user's browser
back to the gift selection page ( list.php ) with the message we prepared earlier indicating
the success or failure of the operation. In practice, when the user clicks on the add or
remove link in list.php , the browser requests the action.php script; this quietly performs
the update and redirects the browser to the list.php page, leaving the user with the
impression that they never left the list page:
// Redirect the browser back to list.php
header("Location: list.php?message=" . urlencode($message));
exit;
Figure 15-4 shows the list of gifts and reserved gifts.
Adding a Gift
If the requested action is to add the gift to the user's shopping list, we should ensure
that we reserve the gift only if it is still free. The gift was free when it was listed by the
list.php script; however, another user could have been viewing the list of gifts at the
 
Search WWH ::




Custom Search