Presentation is loading. Please wait.

Presentation is loading. Please wait.

PRACTICAL PHP AND MYSQL WALKTHROUGH USING SAMPLE CODES – MAX NG.

Similar presentations


Presentation on theme: "PRACTICAL PHP AND MYSQL WALKTHROUGH USING SAMPLE CODES – MAX NG."— Presentation transcript:

1 PRACTICAL PHP AND MYSQL WALKTHROUGH USING SAMPLE CODES – MAX NG

2 WHY PHP AND MYSQL? Easy to learn and install Free to use and readily for download LAMP is a solution stack of free, open source software.solution stackfreeopen source Rich resources in WWW Well supported in PolyU COMP lab

3 PHP IN POLYU COMP LAB PHP (Apache) PHP files are to be placed in :/webhome/ /public_html Solaris Cluster Machine can be accessed thr PC using  WINSCP (file transfer)  PuTTY (Line command session) The website can be accessed using Web browser to the url link : http:/www.comp.polyu.edu.hk/~ /index.phpwww.comp.polyu.edu.hk/~<your

4 MYSQL IN POLYU COMP LAB MySQL A MySQL account is readily activated for your perusal. Account Details:  Host: mysql.comp.polyu.edu.hk:3306  User:  Password:  Schema: To directly manipulate your schema thr’ PC:  In Lab PC, there is a GUI Tool: "COMP" ->"Network Application Packages" ->"Database" - >"MySQL" ->"MySQLQBrowser“

5 WE WILL WALKTHROUGH PHP AND MYSQL TOGETHER Purpose oriented Start from Database table preparation To website implementation Using a simple website to study some basic coding technique My Book Store Using a advanced website to walkthrough a e-commerce system My Web Shop

6 AT THE END OF SESSION, WE SHOULD BE ABLE TO USE THE PROVIDED CODE TO BUILD A SIMPLE WEB SITE. 1.MySQL table setup  Create table  Insert record 2.Write PHP page  Connect to MySQL  Take the http-get parameters  Handle session  Looping control  Generate dynamic web page thr select statement

7 BASIC WEB PAGE DESIGN OF “MY BOOK STORE” 1.Request user login 2.Show product list and selection 3.Purchase list summary index.php books.php summary_order.php

8 WE HAVE TO CREATE A SCHEMA AT FIRST IN MYSQL. 1.Create the schema to house our new table. CREATE DATABASE ; Note: a.To remove the schema, we issue DROP DATABASE ; b.In COMP lab, we use only our login ID as our default schema. 2.Change our session to another schema by issuing USE ;

9 WE PUT THE BOOKLIST TABLE INTO THE ACTIVE SCHEMA. 1.Create table by issuing CREATE TABLE [IF NOT EXISTS] (,... PRIMARY KEY( ), FOREIGN KEY ( ) REFERENCES ( ) ) ; E.g. CREATE TABLE book_records_store( Book_No BIGINT NOT NULL AUTO_INCREMENT, Book VARCHAR(150) NOT NULL, Price DECIMAL(5,2) NOT NULL, PRIMARY KEY(Book_No))ENGINE=MyISAM AUTO_INCREMENT=1;

10 WE INSERT RECORDS INTO THE BOOKLIST TABLE. 1.Insert record by issuing INSERT INTO VALUES (,,...),... e.g. INSERT INTO book_records_store VALUES (null,'C++ for Starters','125.50'), (null,'Java AWT Package','178.50');

11 FINALLY, WE INSPECT THE TABLE CONTENT. Review the schemas we have  SHOW DATABASES; Set active schema by issuing  USE ; Review all table names in a schema  SHOW TABLES; Browse the table content  SELECT * | AS,..., AS FROM WHERE GROUP BY ORDER BY ASC|DESC,... HAVING LIMIT | ; e.g. SELECT * FROM book_records_store ;

12 BASIC WEB PAGE DESIGN OF “MY BOOK STORE” 1.Request user login 2.Show product list and selection 3.Purchase list summary index.php books.php summary_order.php

13 THE SIMPLEST FORM OF PHP PAGE IS ACTUALLY A PAGE OF HTML TAG. Index.php

14 WE HAVE TO PASS INPUT VALUES FROM INDEX.PHP TO BOOKS.PHP USING HTTP-GET … … http://.../books.php?fname=Max&lname=Ng&Loging=Login index.php books.php (1) (2) (3) (2)

15 BASIC WEB PAGE DESIGN OF “MY BOOK STORE” 1.Request user login 2.Show product list and selection 3.Purchase list summary index.php books.php summary_order.php

16 WE SHOW THE LIST OF BOOKS IN OUR BOOKLIST TABLE IN THE BOOKS.PHP

17 PHP CODE IS EMBEDDED INTO HTML PAGE TO GENERATE THE BOOKLIST TABLE. 1.First of all, we connect to the database we just created and build our database query. include is to take the code from another php file and evaluate. databaseconfig.php

18 NEXT, CREATE SESSION TO LET VALUES TO BE AVAILABLE THROUGHOUT SESSION [2] $_GET: Return the http-get variable. Do you remember what is this variable? [4] $_REQUEST: Return the variable either in the array variables in http-get, http-post or cookies. [3] session_start(): start a session [5] $_SESSION: refer to a session variable to be available throughout the session [1] isset() : check null [1] [2] [3] [4] [5]

19 LASTLY, EXTRACT THE DATABASE QUERY RETURN AND CONSTRUCT THE BOOKLIST TABLE [1] [1] mysql_fetch_array() : Fetch a result row as an array [2] [2] echo : output http text [3] [3] in calling order_summary.php, http-get will pass an array with name “order[]” and value which is the price of the book.

20 ONLY THE CHECKBOX = ‘Y’ WILL BE HTTP-GET TO THE SUMMARY_ORDER.PHP http://.../order_summary.php?order%5B%5D=125.50 &order%5B%5D=186.75&order%5B%5D=189.00&Ord =Order

21 BASIC WEB PAGE DESIGN OF “MY BOOK STORE” 1.Request user login 2.Show product list and selection 3.Purchase list summary index.php books.php summary_order.php

22 SUMMARY_ORDER.PHP CONSTRUCT THE ORDER TABLE AND OUTPUT AS HTTP PAGE [1] [1] session_start() : Retrieve the saved session. Now the session variable “firstN” and “lastN” available. [2] [2] count() : count the no. of element in an array [?] [?] We will discuss in the coming lab session.

23 SUMMARY_ORDER.PHP CONSTRUCT THE ORDER TABLE AND OUTPUT AS HTTP PAGE (CONT’D)

24 AT THE END OF SESSION, WE SHOULD BE ABLE TO USE THE PROVIDED CODE TO BUILD A SIMPLE WEB SITE. 1.MySQL table setup  Create table  Insert record 2.Write PHP page  Connect to MySQL  Take the http-get parameters  Handle session  Looping control  Generate dynamic web page thr select statement

25 FUNCTIONAL WALKTHROUGH: A ECOMMERCE SYSTEM USING PHP AND MYSQL

26 A COMPREHENSIVE ECOMMERCE SITE SHOULD BE ABLE TO: 1.Handle customer request in timely fashion 2.Provide sufficient information for customer to make purchase decision 3.Smoothen the process from product selection to payment 4.Maintain the product list and stock control 5.Maintain the order information 6.Maintain the customer information 7.Perform web advertising and site analytics

27 PRODUCT LIST INTEGRATED WITH SHOPPING CART

28 SHOPPING CART PROVIDED WITH DIRECT CHECKOUT OR BACK TO SHOPPING

29 CHECK OUT, PAYMENT AND EMAIL NOTIFICATION ALL- DO IN ONE-TAKE

30 ADMINISTRATION: CATALOG, ORDER MANAGEMENT AND MINOR SCREEN LAYOUT

31 CATALOG MANAGEMENT ON PRODUCT, FEATURED PRODUCT LIST AND STOCK MANAGEMENT

32 TRACE CUSTOMER NEW ORDER AND FURTHER BACKEND PROCESSING

33 COMPREHENSIVE SITE CONFIGURATION ON VARIOUS SETTINGS

34 Thanks!!


Download ppt "PRACTICAL PHP AND MYSQL WALKTHROUGH USING SAMPLE CODES – MAX NG."

Similar presentations


Ads by Google