Appendix A. The Wedding Registry Code

Overview

In this appendix, we list the complete code of the wedding registry application we developed in Chapter 15. This code is also available for download from the book’s web site.

Example A-1 contains the code in action.php; Example A-2 contains the code in db.php; Example A-3 contains the disclaimer code; Example A-4 contains the code in edit.php; Example A-5 contains the code in index.php; Example A-6 contains the text in license.txt; Example A-7 contains the code in list.php; and Example A-8 contains the code in logout.php.

Example A-1. action.php

<?php // action.php: Add or remove a gift from the user's shopping list // Include database parameters and related functions require_once("db.php"); // Check if the user is logged in // (this also starts the session) logincheck(); // Secure the user data if(count($_GET)) { // 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); $gift_id = clean($_GET['gift_id'], 5); $action = clean($_GET['action'] , 6); // Is the action something we know about? if($action != "add" && $action != "remove") // No, it's not; perhaps someone's trying to manipulate the // URL query string? die("Unknown action: ".$action); // The program should reach this point only if the action is add // or remove, since otherwise processing stops with the die() // instruction. ...

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.