// Lane, "Web Database Application with PHP and MySQL" published by O'Reilly & // Associates. // // This code is under copyright and cannot be included in any other book, // publication, or educational product without permission from O'Reilly & // Associates. No warranty is attached; we cannot take responsibility for errors // or fitness for use. // This is the script that allows the to search and browse wines, and // to select wines to add to their shopping cart require_once "../includes/template.inc"; require_once "../includes/winestore.inc"; set_error_handler("customHandler"); session_start(); // Takes <form> heading, instructions, action, formVars name, and // formErrors name as parameters $template = new winestoreFormTemplate("Search", "Choose regions and wine types to browse.", S_SEARCH, "searchFormVars", NULL, "GET"); $connection = DB::connect($dsn, true); if (DB::isError($connection)) { trigger_error($connection->getMessage(), E_USER_ERROR); } // Create the drop-down search widgets for the page // Load the regions from the region table $regionResult = $connection->query("SELECT * FROM region"); if (DB::isError($regionResult)) { trigger_error($regionResult->getMessage(), E_USER_ERROR); } // Load the wine types from the wine_type table $wineTypeResult = $connection->query("SELECT * FROM wine_type"); if (DB::isError($wineTypeResult)) { trigger_error($wineTypeResult->getMessage(), E_USER_ERROR); }
// that contain erroneous data: errors are generated // by validate.php require_once "DB.php"; require_once "../includes/winestore.inc"; require_once "../includes/authenticate.inc"; require_once "../includes/template.inc"; set_error_handler("customHandler"); // Show meaningful instructions for UPDATE or INSERT if (isset($_SESSION["loginUsername"])) { $instructions = "Please amend your details below as required."; } else { $instructions = "Please fill in the details below to join."; } // Takes <form> heading, instructions, action, formVars name, and formErrors // name as parameters $template = new winestoreFormTemplate("Customer Details", $instructions, S_VALIDATE, "custFormVars", "custErrors"); session_start(); $connection = DB::connect($dsn, true); if (DB::isError($connection)) { trigger_error($connection->getMessage(), E_USER_ERROR); } // Is the user logged in and are there no errors from previous // validation? If so, look up the customer for editing if (isset($_SESSION["loginUsername"]) && !isset($_SESSION["custErrors"])) { // Check the user is properly logged in sessionAuthenticate(S_MAIN); $query = "SELECT title_id, surname, firstname, initial, address,\n city, state, zipcode, country_id, phone, \n birth_date \n FROM users, customer \n WHERE users.cust_id = customer.cust_id \n AND user_name = '{$_SESSION["loginUsername"]}'"; $result = $connection->query($query); if (DB::isError($result)) { trigger_error($result->getMessage(), E_USER_ERROR); }
// Author: Hugh E. Williams, 2001-3 // // Unless otherwise stated, the source code distributed with this book can be // redistributed in source or binary form so long as an acknowledgment appears // in derived source files. // The citation should list that the code comes from Hugh E. Williams and David // Lane, "Web Database Application with PHP and MySQL" published by O'Reilly & // Associates. // // This code is under copyright and cannot be included in any other book, // publication, or educational product without permission from O'Reilly & // Associates. No warranty is attached; we cannot take responsibility for errors // or fitness for use. // This script shows the user a <form> to change their password // The user must be logged in to view it. require_once "../includes/template.inc"; require_once "../includes/winestore.inc"; require_once "../includes/authenticate.inc"; set_error_handler("customHandler"); session_start(); // Check the user is properly logged in sessionAuthenticate(S_MAIN); // Takes <form> heading, instructions, action, formVars name, and formErrors // name as parameters $template = new winestoreFormTemplate("Change Password", "Please enter your existing and new passwords.", S_CHANGEPASSWORD, "pwdFormVars", "pwdErrors"); // Create the password change widgets $template->passwordWidget("currentPassword", "Current Password:"******"newPassword1", "New Password:"******"newPassword2", "Re-enter New Password:", 8); // Add buttons and messages, and show the page $template->showWinestore(NO_CART, B_HOME);
// Author: Hugh E. Williams, 2001-3 // // Unless otherwise stated, the source code distributed with this book can be // redistributed in source or binary form so long as an acknowledgment appears // in derived source files. // The citation should list that the code comes from Hugh E. Williams and David // Lane, "Web Database Application with PHP and MySQL" published by O'Reilly & // Associates. // // This code is under copyright and cannot be included in any other book, // publication, or educational product without permission from O'Reilly & // Associates. No warranty is attached; we cannot take responsibility for errors // or fitness for use. // This script allows a user to enter their credit card number // and delivery instructions. // The user must be logged in to view it. require_once "../includes/template.inc"; require_once "../includes/winestore.inc"; require_once "../includes/authenticate.inc"; set_error_handler("customHandler"); session_start(); // Check the user is properly logged in sessionAuthenticate(S_SHOWCART); // Takes form heading, instructions, action, formVars name, and // formErrors name as parameters $template = new winestoreFormTemplate("Finalise Your Order", "Please enter your SurchargeCard details " . "(Try: 8000000000001001 ) and delivery instructions.", S_ORDER_2, "ccFormVars", "ccErrors"); // Create the credit card widgets $template->mandatoryWidget("creditcard", "SurchargeCard:", 16); $template->mandatoryWidget("expirydate", "Expiry Date (mm/yy):", 5); $template->optionalWidget("instructions", "Delivery Instructions:", 128); $template->showWinestore(SHOW_ALL, B_SHOW_CART | B_HOME);
<?php // Source code example for Web Database Applications with PHP and MySQL, 2nd Edition // Author: Hugh E. Williams, 2001-3 // // Unless otherwise stated, the source code distributed with this book can be // redistributed in source or binary form so long as an acknowledgment appears // in derived source files. // The citation should list that the code comes from Hugh E. Williams and David // Lane, "Web Database Application with PHP and MySQL" published by O'Reilly & // Associates. // // This code is under copyright and cannot be included in any other book, // publication, or educational product without permission from O'Reilly & // Associates. No warranty is attached; we cannot take responsibility for errors // or fitness for use. // Show the login page require_once "../includes/template.inc"; require_once "../includes/winestore.inc"; require_once "../includes/validate.inc"; set_error_handler("customHandler"); session_start(); // Takes <form> heading, instructions, action, formVars name, and // formErrors name as parameters $template = new winestoreFormTemplate("Login", "Please enter your username and password.", S_LOGINCHECK, "loginFormVars", "loginErrors"); $template->mandatoryWidget("loginUsername", "Username/Email:", 50); $template->passwordWidget("loginPassword", "Password:", 8); // Add buttons and messages, and show the page $template->showWinestore(NO_CART, B_HOME);