PHP and MySQL for Client-Server Database Interaction Chapter 10.

Slides:



Advertisements
Similar presentations
PHP Form and File Handling
Advertisements

PHP SQL. Connection code:- mysql_connect("server", "username", "password"); Connect to the Database Server with the authorised user and password. Eg $connect.
Widhy Hayuhardhika NP, S.Kom. Overview of database structure Connecting to MySQL database Selecting the database to use Using the require_once statement.
UFCE8V-20-3 Information Systems Development 3 (SHAPE HK)
Cookies, Sessions. Server Side Includes You can insert the content of one file into another file before the server executes it, with the require() function.
09/04/2015Unit 2 (b) Back-Office processes Unit 2 Assessment Criteria (b) 10 marks.
PHP Hypertext Preprocessor Information Systems 337 Prof. Harry Plantinga.
Lecture 6/2/12. Forms and PHP The PHP $_GET and $_POST variables are used to retrieve information from forms, like user input When dealing with HTML forms.
PRACTICAL PHP AND MYSQL WALKTHROUGH USING SAMPLE CODES – MAX NG.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Web Database Programming Using PHP.
Computer Science 101 Web Access to Databases Overview of Web Access to Databases.
PHP Tutorials 02 Olarik Surinta Management Information System Faculty of Informatics.
Application Development Description and exemplification of server-side scripting language for server connection, database selection, execution of SQL queries.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Cookies & Sessions.
Cookies Set a cookie – setcookie() Extract data from a cookie - $_COOKIE Augment user authentication script with a cookie.
MySQL in PHP – Page 1 of 17CSCI 2910 – Client/Server-Side Programming CSCI 2910 Client/Server-Side Programming Topic: MySQL in PHP Reading: Williams &
INTERNET APPLICATION DEVELOPMENT For More visit:
CHAPTER 12 COOKIES AND SESSIONS. INTRO HTTP is a stateless technology Each page rendered by a browser is unrelated to other pages – even if they are from.
Create an online booking system (login/registration)
WNS1.com Online Training How to use the Western Nevada Supply online store and tools.
Getting started on informaworld™ How do I register my institution with informaworld™? How is my institution’s online access activated? What do I do if.
Your on-line connection to Ferraz Shawmut; Getting Started Login / out Contact Us Home Page, Account Inquiry My E-Account Account Status Ordering Options.
NMED 3850 A Advanced Online Design January 26, 2010 V. Mahadevan.
SHOPPING CARTS CHAPTER 19. E-COMMERCE Typically, an e-commerce site will have public pages and admin pages.
CS453: State in Web Applications (Part 1) State in General Sessions (esp. in PHP) Prof. Tom Horton.
PHP meets MySQL.
COMP3121 E-Commerce Technologies Richard Henson University of Worcester November 2011.
Chapter 8 Cookies And Security JavaScript, Third Edition.
12/3/2012ISC329 Isabelle Bichindaritz1 PHP and MySQL Advanced Features.
15/10/20151 PHP & MySQL 'Slide materials are based on W3Schools PHP tutorial, 'PHP website 'MySQL website.
PHP MySQL Introduction. MySQL is the most popular open-source database system. What is MySQL? MySQL is a database. The data in MySQL is stored in database.
School of Computing and Information Systems CS 371 Web Application Programming PHP – Forms, Cookies, Sessions and Database.
SYST Web Technologies SYST Web Technologies Databases & MySQL.
Week seven CIT 354 Internet II. 2 Objectives Database_Driven User Authentication Using Cookies Session Basics Summary Homework and Project 2.
Once you have located the ISBN you would like to purchase, click “Add to Cart”. You will get a pop-up window showing the item you’ve added. If you are.
PHP1-1 PHP Lecture 2 Xingquan (Hill) Zhu
Lecture 8 – Cookies & Sessions SFDV3011 – Advanced Web Development 1.
Nic Shulver, Introduction to Sessions in PHP Sessions What is a session? Example Software Software Organisation The login HTML.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
Chapter 9 Session Tracking. Session Tracking Basics Accessing the session object associated with the current request: Call request.getSession to get an.
PHP. $_GET / $_POST / $_SESSION PHP uses predefined variables to provide access to important information about the server and requests from a browser.
Cookies and Sessions IDIA 618 Fall 2014 Bridget M. Blodgett.
Controlling Web Site Access Using Logins CS 320. Basic Approach HTML form a php page that collects the username and password  Sends them to second PHP.
 Registry itself is easy and straightforward in implementation  The objects of registry are actually complicated to store and manage  Objects of Registry.
NMD202 Web Scripting Week5. What we will cover today PHP & MySQL Displaying Dynamic Pages Exercises Modifying Data PHP Exercises Assignment 1.
Creating a simple database This shows you how to set up a database using PHPMyAdmin (installed with WAMP)
 Shopping Basket  Stages to maintain shopping basket in framework  Viewing Shopping Basket.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Database Access Control IST2101. Why Implementing User Authentication? Remove a lot of redundancies in duplicate inputs of database information – Your.
SESSIONS 27/2/12 Lecture 8. ? Operator Similar to the if statement but returns a value derived from one of two expressions by a colon. Syntax: (expression)
IS2803 Developing Multimedia Applications for Business (Part 2) Lecture 1: Introduction to IS2803 Rob Gleasure
ITM © Port,Kazman 1 ITM 352 Cookies. ITM © Port,Kazman 2 Problem… r How do you identify a particular user when they visit your site (or any.
1 PHP HTTP After this lecture, you should be able to know: How to create and process web forms with HTML and PHP. How to create and process web forms with.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Web Database Programming Using PHP.
CSCI 6962: Server-side Design and Programming Shopping Carts and Databases.
Unit-6 Handling Sessions and Cookies. Concept of Session Session values are store in server side not in user’s machine. A session is available as long.
MYSQL AND MYSQL WORKBENCH MIS2502 Data Analytics.
CGS 3066: Web Programming and Design Spring 2016 PHP.
PHP: Further Skills 02 By Trevor Adams. Topics covered Persistence What is it? Why do we need it? Basic Persistence Hidden form fields Query strings Cookies.
Sessions and cookies MIS 3501, Spring 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 4/12/2016.
Flash Board MX PHP Files CISC 254. Fix for Global Variables foreach($HTTP_GET_VARS as $name => $value) { $$name = $value;} foreach($HTTP_POST_VARS as.
Web Database Programming Using PHP
Advanced Web Development IT225
Web Database Programming Using PHP
Web Design and Development
ITM 352 Cookies.
Web Systems Development (CSC-215)
Web DB Programming: PHP
Web Programming Language
Presentation transcript:

PHP and MySQL for Client-Server Database Interaction Chapter 10

Overview and Objectives: New Functionality Browse through our product catalog without registering (that is, “anonymously”) Open an account by registering with our website Log in to our website as a registered user, and later log out Browse through our product catalog as a registered user, order various items online, and manage a shopping cart Purchase the shopping cart items and then check out Chapter 10: PHP and MySQL for Client-Server Database Interaction

Skills That Will Be Learned How a PHP script connects to a MySQL database How a PHP script issues queries about customers or products to a MySQL database and then receives and processes the replies More about PHP arrays How to use a PHP session to keep track of a user’s activity during a visit to our website Chapter 10: PHP and MySQL for Client-Server Database Interaction

Current State of Our Website Chapter 10: PHP and MySQL for Client-Server Database Interaction Courtesy of Nature’s Source. Inset © Photos.com

Bird's Eye View of e-store Functionality Chapter 10: PHP and MySQL for Client-Server Database Interaction Courtesy of Nature’s Source.

PHP Code for Connecting to MySQL <?php //db.php $db_location = "localhost"; $db_username = "webbook"; $db_password = "secret"; $db_database = "webbook"; $db_connection = mysql_connect("$db_location","$db_username","$db_password") or die ("Error - Could not connect to MySQL Server"); $db = mysql_select_db($db_database,$db_connection) or die ("Error - Could not open database"); ?> Information supplied: The location of the MySQL server ($db location ) The user’s MySQL username ($db username ) The user’s password ($db password ) Chapter 10: PHP and MySQL for Client-Server Database Interaction Important Start

Registering for Our Web Site Chapter 10: PHP and MySQL for Client-Server Database Interaction Courtesy of Nature’s Source. You can go to the CD and get this page as a starting point, then edit it.

Registration Scenarios During the registration process we must be prepared to deal with at least the following possible scenarios: – Successful registration – Does not pass JavaScript validation on the client side – Already registered and has perhaps forgotten they have done so, which will be recognized when the user is discovered to be in the database already – Choosing a login name that is already in use Chapter 10: PHP and MySQL for Client-Server Database Interaction

XHTML and PHP Code for the Registration Form Chapter 10: PHP and MySQL for Client-Server Database Interaction These are.php files

Validating the Form Data (1 of 3) Chapter 10: PHP and MySQL for Client-Server Database Interaction

Validating the Form Data (2 of 3) Chapter 10: PHP and MySQL for Client-Server Database Interaction

Validating the Form Data (3 of 3) Chapter 10: PHP and MySQL for Client-Server Database Interaction

The php files for the customer registration process Chapter 10: PHP and MySQL for Client- Server Database Interaction db.php Simply opens the database connection and saves it as a variable processRegistration.php This does the actual query to save the data to the database. Also contains the functions to handle the exceptions registration.php Calls the processRegistration script/page and provides a place to return to when the processing is done. Not very big register.php This is the page that the user will enter into the url to open up. It all starts from here. It has the form in it to collect the data. (also calls validation) I suggest we start with trying to add someone to our customer table.

Messages Chapter 10: PHP and MySQL for Client-Server Database Interaction Courtesy of Nature’s Source.

Re-registering for the Site with Different but Same Username Chapter 10: PHP and MySQL for Client-Server Database Interaction Courtesy of Nature’s Source.

XHTML and PHP Code for Processing the Registration Data Chapter 10: PHP and MySQL for Client-Server Database Interaction Built in function to start maintaining the idea “state” or “session” variables.

Main Program from processRegistration.php (1 of 2) Chapter 10: PHP and MySQL for Client-Server Database Interaction

Main Program from processRegistration.php (2 of 2) Chapter 10: PHP and MySQL for Client-Server Database Interaction Check next slide to use the $_POST superglobal to actual grab the data the user typed in to the form.

Chapter 10: PHP and MySQL for Client- Server Database Interaction VALUES ( NULL, '$_POST[firstName]', '$_POST[middleInitial]', '$_POST[lastName]', '$_POST[ ]', '$unique_login', '$_POST[loginPassword]', '$_POST[phone]', '$_POST[address]', '$_POST[city]', '$_POST[state]', '$_POST[zip]', '$_POST[country]');"; I believe this correct Notice the addition of “ ‘$_POST[…….]’”

A Helper Function from processRegistration.php Chapter 10: PHP and MySQL for Client-Server Database Interaction

Another Helper Function from processRegistration.php Chapter 10: PHP and MySQL for Client-Server Database Interaction

PHP Arrays php > //The following command creates an array: php > $a[] = "Hello"; php > //We omitted the subscript so the next available php > //subscript is used, which is 0 in this case. Chapter 10: PHP and MySQL for Client-Server Database Interaction php > //Cannot use the echo command to print an array. php > echo $a; Array php > //But... the echo command can print elements of an array. php > echo $a[0]; Hello

PHP Arrays php > //Let us now add a number of elements to our array. php > $a[] = "World"; php > $a[-90] = "This is wild"; php > $a[90] = "This is wild"; php > $a[70] = "This is wild"; php > $a[name] = "Pawan"; Chapter 10: PHP and MySQL for Client-Server Database Interaction

PHP Arrays php > //You can use the print_r() function to print an entire array. php > print_r($a); Array ( [0] => Hello [1] => World [-90] => This is wild [90] => This is wild [70] => This is wild [name] => Pawan ) php > //As we can see, the indexes are not ordered as you would have php > //expected, since -90 comes after 1, and 70 comes after 90. Chapter 10: PHP and MySQL for Client-Server Database Interaction

PHP Arrays php > //You can delete an element using the function unset php > unset($a[-90]); php > print_r($a); Array ( [0] => Hello [1] => World [90] => This is wild [70] => This is wild [name] => Lingras ) php > //The count() gives you the size of an array. php > echo count($a); 7 Chapter 10: PHP and MySQL for Client-Server Database Interaction

PHP Arrays php > //The "construct" array() (not a function) can be used to create an entire array. php > $a = array("This", "is", "different", 5, 6, 7); php > print_r($a); Array ( [0] => This [1] => is [2] => different [3] => 5 [4] => 6 [5] => 7 ) Chapter 10: PHP and MySQL for Client-Server Database Interaction

PHP Arrays: Summary A PHP array index is really just a means of accessing a particular element in an array. It does not necessarily suggest an ordering. That is why we can use -90 as an index, which is stored in the array after the index 1. If we do not use an index to place a value in an array, the first numeric index greater than the last-used numeric index is used. Array elements can be displayed using echo, but you need to use the built-in function print_r() to print an entire array. A function called count() gives us the size of an array. An entire array can be created by using the array() construct. If we want conventionally ordered numeric indices from an associative array, we can use the function array_values(). Chapter 10: PHP and MySQL for Client-Server Database Interaction

$_SESSION Super global Array containing session variables available as a global (that you define the index) Temporarily store data specific to a particular user while he/she surfs your website. data is stored on web server At the beginning of your script, make a call to the session_start() function Chapter 10: PHP and MySQL for Client- Server Database Interaction

Logging In to the e-store Chapter 10: PHP and MySQL for Client-Server Database Interaction Courtesy of Nature’s Source.

Opening Lines of PHP Code and XHTML Markup for the Login Form Chapter 10: PHP and MySQL for Client-Server Database Interaction

JavaScript Code for Validating the Login Form Data Entries Chapter 10: PHP and MySQL for Client-Server Database Interaction

Rest of the XHTML Markup and PHP Code for the Login Form (1 of 2) Chapter 10: PHP and MySQL for Client-Server Database Interaction

Rest of the XHTML Markup and PHP Code for the Login Form (2 of 2) Chapter 10: PHP and MySQL for Client-Server Database Interaction

PHP Code: Processing Login Form (1 of 2) Chapter 10: PHP and MySQL for Client-Server Database Interaction From the login page Load the session array

PHP Code: Processing Login Form (2 of 2) Chapter 10: PHP and MySQL for Client-Server Database Interaction Page it came from

Request For a User to Try Again after a Failed Login Chapter 10: PHP and MySQL for Client-Server Database Interaction Courtesy of Nature’s Source.

Passing Key/Value Pairs in a URL $goto = "Location:../purchase.php?prod=$prod"; header('Location:../login.php?retry=true'); At the end of each of these lines we see a ? separating a key/value pair in which the key and value are themselves separated by an equals sign. The value half of the pair can be provided as a literal value ( true ) or as a variable ( $prod ). More than one key/value pair can be passed along in this way, in which case an & separates the key/value pairs: login.php?retry=true&otherKey=otherValue Chapter 10: PHP and MySQL for Client-Server Database Interaction

PHP Code for Processing the Logout (1 of 2) Chapter 10: PHP and MySQL for Client-Server Database Interaction Destroy the session

PHP Code for Processing the Logout (2 of 2) Chapter 10: PHP and MySQL for Client-Server Database Interaction

Display Indicating a Successful Logout Chapter 10: PHP and MySQL for Client-Server Database Interaction Courtesy of Nature’s Source.

Display When an Attempt is Made to Log Out Without Having Logged In Chapter 10: PHP and MySQL for Client-Server Database Interaction Courtesy of Nature’s Source.

e-store After Successful Login Chapter 10: PHP and MySQL for Client-Server Database Interaction Courtesy of Nature’s Source.

Revised banner.php (1 of 2) Chapter 10: PHP and MySQL for Client-Server Database Interaction

Revised banner.php (2 of 2) Chapter 10: PHP and MySQL for Client-Server Database Interaction

Listing of the Departments and Product Categories in Our e-store Chapter 10: PHP and MySQL for Client-Server Database Interaction Courtesy of Nature’s Source.

PHP Code for Displaying Departments and Categories (1 of 2) Chapter 10: PHP and MySQL for Client-Server Database Interaction

PHP Code for Displaying Departments and Categories (2 of 2) Chapter 10: PHP and MySQL for Client-Server Database Interaction Use a query to display the department

A listing of the Individual Products in a Category Chapter 10: PHP and MySQL for Client-Server Database Interaction Courtesy of Nature’s Source.

PHP Code for Displaying Products in a Category (1 of 2) Chapter 10: PHP and MySQL for Client-Server Database Interaction

PHP Code for Displaying Products in a Category (2 of 2) Chapter 10: PHP and MySQL for Client-Server Database Interaction Building an HTML table from the numRecords result and a loop

Chapter 10: PHP and MySQL for Client- Server Database Interaction

Purchasing a First Product Chapter 10: PHP and MySQL for Client-Server Database Interaction Courtesy of Nature’s Source.

Purchasing Additional Products: Trying to Buy More than the Stock Chapter 10: PHP and MySQL for Client-Server Database Interaction Courtesy of Nature’s Source.

Try Again: Do not Request More than Available Chapter 10: PHP and MySQL for Client-Server Database Interaction Courtesy of Nature’s Source.

Viewing the Shopping Cart with Two Items: Ready for Checkout Chapter 10: PHP and MySQL for Client-Server Database Interaction Courtesy of Nature’s Source.

PHP Code for Main Part of the PHP Script for Processing Purchases (1 of 3) Chapter 10: PHP and MySQL for Client-Server Database Interaction

PHP Code for Main Part of the PHP Script for Processing Purchases (2 of 3) Chapter 10: PHP and MySQL for Client-Server Database Interaction

PHP Code for Main Part of the PHP Script for Processing Purchases (3 of 3) Chapter 10: PHP and MySQL for Client-Server Database Interaction

PHP Function for Retrieving Product Information for an Order-in-progress Chapter 10: PHP and MySQL for Client-Server Database Interaction

PHP Function for Creating a New Order Chapter 10: PHP and MySQL for Client-Server Database Interaction

PHP Function for Displaying the Table Header for the Shopping Cart Display Chapter 10: PHP and MySQL for Client-Server Database Interaction

PHP Function for Displaying the Table Footer for the Shopping Cart Display Chapter 10: PHP and MySQL for Client-Server Database Interaction

PHP Function for Displaying the First Four Table Columns for a Product Chapter 10: PHP and MySQL for Client-Server Database Interaction

PHP Function for Displaying the Last Three Columns for Each Existing Item Chapter 10: PHP and MySQL for Client-Server Database Interaction

PHP Function for Displaying the Last Three Columns for Each New Item Chapter 10: PHP and MySQL for Client-Server Database Interaction

PHP Code for Adding a New Item to the Cart (1 of 3) Chapter 10: PHP and MySQL for Client-Server Database Interaction

PHP Code for Adding a New Item to the Cart (2 of 3) Chapter 10: PHP and MySQL for Client-Server Database Interaction

PHP Code for Adding a New Item to the Cart (3 of 3) Chapter 10: PHP and MySQL for Client-Server Database Interaction

PHP Code for Deleting an Item from the Cart Chapter 10: PHP and MySQL for Client-Server Database Interaction

A Shopping Cart with a Single Item: Ready for Checkout Chapter 10: PHP and MySQL for Client-Server Database Interaction Courtesy of Nature’s Source.

Receipt Displayed upon Completion of the Checkout Process Chapter 10: PHP and MySQL for Client-Server Database Interaction Courtesy of Nature’s Source.

Confirming the Reduction in Inventory after Purchase Chapter 10: PHP and MySQL for Client-Server Database Interaction Courtesy of Nature’s Source.

XHTML and PHP Code for Relevant Parts from payment.php Chapter 10: PHP and MySQL for Client-Server Database Interaction

PHP Code the Main Part of the Script for Processing a Payment Chapter 10: PHP and MySQL for Client-Server Database Interaction

PHP Function for Marking an Order as Paid (1 of 2) Chapter 10: PHP and MySQL for Client-Server Database Interaction

PHP Function for Marking an Order as Paid (2 of 2) Chapter 10: PHP and MySQL for Client-Server Database Interaction

PHP Function for Marking Each Individual Item as Paid (1 of 2) Chapter 10: PHP and MySQL for Client-Server Database Interaction

PHP Function for Marking Each Individual Item as Paid (2 of 2) Chapter 10: PHP and MySQL for Client-Server Database Interaction

PHP Function for Reducing the Inventory Level After Payment (1 of 2) Chapter 10: PHP and MySQL for Client-Server Database Interaction

PHP Function for Reducing the Inventory Level After Payment (2 of 2) Chapter 10: PHP and MySQL for Client-Server Database Interaction