Presentation is loading. Please wait.

Presentation is loading. Please wait.

Website Development Database Issues. : Customer browser request service access page interpret set data present html return html get data databasescripting.

Similar presentations


Presentation on theme: "Website Development Database Issues. : Customer browser request service access page interpret set data present html return html get data databasescripting."— Presentation transcript:

1 Website Development Database Issues

2 : Customer browser request service access page interpret set data present html return html get data databasescripting language web server Reminder of the general process

3 The Guestbook Database is a Bit Weedy

4 Two Tables CREATE TABLE forum_topics ( topic_id int NOT NULL AUTO_INCREMENT, PRIMARY KEY(topic_id), topic_title varchar(150), topic_create_time datetime, topic_owner varchar (150) ); CREATE TABLE forum_posts ( post_id int NOT NULL AUTO_INCREMENT, PRIMARY KEY(post_id), topic_id int not null, post_text text, post_create_time datetime, post_owner varchar (150) ); Test

5 Remember this?

6 The Northwind Database Would be a very good database for an example e:commerce application Better if it were implemented in MySQL We can “reverse engineer” an entity model from the database using Visio.

7

8 Forward engineering the model into MySQL

9

10

11 Let’s get some data in those tables and so on…..

12 How can we get from that to… A working online ordering system An administrative system for the online ordering system

13 “Skeleton” Functionality Registration of users Logging in Admin and normal rights Adding products Navigation Adding to shopping basket Ordering Viewing users Viewing orders Viewing baskets

14 Registration User Name Password Registeringregister.htm

15 What do we need to do now? Check to see if anyone has used that password already. If not add the new user to our table of registered users. This is dealt with in saveUser.php

16 $query = "SELECT PASSWORD FROM $table_users WHERE USERNAME = \"$UserName\""; $result=mysql_query($query); if (mysql_num_rows($result) > 1) { echo("Someone has already used that username "); include('register.htm'); exit(); }; $query = "INSERT INTO $table_users SET USERNAME = \"$UserName\", PASSWORD = \"$Password\""; $result=mysql_query($query); if ($result) { include('loginForm.htm'); }; Adding user recordsaveUser.php

17 What next? Once a user has registered we get them to log in using the standard login form. This is loginForm.htm

18 Log in User Name Password Logging inloginForm.htm

19 What next? This is the standard login form for registered users We now need to find the username in our database and check that the password matches the one we have on record. This is done in loginCheck.php Save the username and password in a cookie so we can remember it for future checks that the user has logged in

20 <?php $User=$UserName; $Pword = $Password; include('loginCheck.php'); include('welcome.php'); ?> Logging in login.php

21 $query = "SELECT PASSWORD FROM $table_users WHERE USERNAME = \"$User\""; $result=mysql_query($query); if (mysql_num_rows($result) == 0) { echo("Not registered "); include('register.htm'); exit(); }; if (mysql_num_rows($result) > 1) { echo("Multiple registration - contact the web master "); exit(); }; $row = mysql_fetch_row($result); if ($row[0] <> $Pword) { echo("Wrong Password"); include('loginForm.htm'); exit(); }; Checking the log in loginCheck.php

22 What next? Now the user can do stuff Add comments to your Guestbook Buy things from Northwind etc.

23 Page Structures Most of the php pages we have created have had the following structure. Connect to the database Create some kind of query Execute the query Display the result.

24 General format of pages for an e:commerce application: Check that the user is logged in and valid Provide the page, pushing code into hidden functions where possible Display navigation

25 Order form <?php chooser(); include('navigation.php'); ?> Choosing products chooseProduct.php

26 Shopping Basket <?php include('loginCheck.php'); showBasket(); include('navigation.php'); ?> Showing the basket showBasket.php

27 <?php include('loginCheck.php'); $dbcnx = myConnect(); $query = "SELECT $table_basket.PROD_ID, $table_basket.CUST_ID, QUANTITY FROM $table_basket, $table_users WHERE $table_basket.CUST_ID = $table_users.CUST_ID AND $table_users.USERNAME = \"$User\""; $result=mysql_query($query); if (! $result) printf ("Error: %s ", mysql_error ()); for ($i = 0; $i < mysql_num_rows ($result); $i++) { $row = mysql_fetch_row($result); $cust_id = $row[1]; $query = "INSERT INTO $table_order SET PROD_ID =".$row[0]. ", QUANTITY = ".$row[2].", CUST_ID = ".$row[1].", DAY = ".date("Ymd"); $result2=mysql_query($query); if (! $result2) printf ("Error: %s ", mysql_error ()); }; if (mysql_num_rows ($result)>0) { $query = "DELETE FROM $table_basket WHERE $table_basket.CUST_ID = $cust_id"; $result=mysql_query($query); if (! $result) printf ("Error: %s ", mysql_error ()); }; echo("ORDER SUBMITTED"); include('navigation.php'); ?> Submitting an order - example of detailed code submitOrder.php

28 <?php viewTable($table_products, ""); addToTable($table_products,"prodEdit.php"); include('navigation.php'); ?> Editing the product table prodEdit.php

29 Choose Product Show Basket Submit Order Add Product All Baskets All Users All Orders Zap Database Show Orders login Navigation and selective functionalitynavigation.php

30 What’s Going On? We are beginning to develop a generic framework of php code for an e:commerce application You could “flesh out” this framework to work with a specific database Provided you are not frightened of php code!


Download ppt "Website Development Database Issues. : Customer browser request service access page interpret set data present html return html get data databasescripting."

Similar presentations


Ads by Google