Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page: ASP PHP...

75
Creating Dynamic Database- Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page: http://projects.coe.uga.edu/workshop/ rieber/ ASP PHP JSP ColdFusion Last updated on November 20, 2008

Transcript of Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page: ASP PHP...

Page 1: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

Creating Dynamic Database-Driven Sites with Dreamweaver

Lloyd Rieber

Workshop Home Page:http://projects.coe.uga.edu/workshop/rieber/

ASPPHPJSP

ColdFusion

Last updated on November 20, 2008

Page 2: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

Recommended: Get and Install the Dreamweaver Extension

'Go To Detail Extension for PHP'

• Here’s the URL:

http://www.adobe.com/cfusion/exchange/index.cfm?event=extensionDetail&extid=627434

(Link is on workshop home page.)

Page 3: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

Workshop Agenda

• Welcome and introductions• Seeing the power of a dynamic web site in

education– Online Introduction to Instructional Design

• Seeing/doing it: Building a small dynamic “people” web site– List current people, add new person, update existing

person

• Advanced topics– Session variables, PHP scripting, Automated Email

Page 4: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

Some of Lloyd’s Examples of Using Online Databases

• Online Introduction to Instructional Design• Other examples

– Project Promote– Peer Financial Counseling– WWILD Team– Introduction to Computers in Education

(Online Course)– EDIT 6170 IDA Library– IDD Portfolio Management

Page 5: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

http://www.nowhereroad.com/instructionaldesign

Page 6: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

Program Flowchart

list.php

insert.phpupdate.php

update_record_reply.htm new_record_reply.htm

Update Record Insert Record

Page 7: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

Here are the files we will eventually create…

Page 8: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

Client requests PHP File

Client

Server

Server returns HTML text to client

Server locates the PHP file on the hard drive and parses it, removing all PHP script and replacing it with HTML text

Client/Server Interaction for PHP Files

Adapted from Mitchell & Atkinson (2000)

Page 9: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

How Databases Work

A 15-Minute Primer

Page 10: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

“Flat” Database Structure

Database

Record Record Record

Field Field Field

Page 11: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

“Flat” Database Structure

Studio People

Lloyd Ike Greg

Database ID Name Course

Page 12: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.
Page 13: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

Relational Database StructureA Collection of Databases (tables) that connect (relate) to each other

Orders

Order1 Order2 Order3

People_ID Order_ID Book_Title Price

People

John Mary Jane

People_ID Name Address Email

Page 15: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.
Page 16: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.
Page 17: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

Working with mySQL DatabasesphpMyAdmin

http://projects.coe.uga.edu/pma

Page 18: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.
Page 19: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

Step 1: Make a root folder

Step 2: Create a folder inside it named:yourLastname

Getting Ready to Work with Dreamweaver

Page 20: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

Step 3: Launch Dreamweaver and define a new site that points to the root folder.

Launch Dreamweaver

Page 21: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

Remote Server Information

Be sure to “Test” your connection before proceeding.

Password:

(this will be changed within a few days)

Notice that this server needs a Secure FTP connection.

eu3$@93!

Page 22: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

Testing Server Information

Be sure to “Test” your connection before proceeding.

Double-check that this URL is correct. (On some servers, you will need to remove server-side pathways, such as “wwwroot”, from the URL Prefix.

Page 23: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

Creating a Simple Search/Results Page Set

Page 24: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

Make a new file called “list.php”

Add a 2 X 4 table and format accordingly:

Page 25: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

Creating a Data ConnectionGo to the Application Panel, click on “Databases” tab, then follow the directions…

Naming convention:

connDescriptive

Use “connLastName” (for reasons I’ll explain)

Page 26: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

Notice that a folder titled “Connections” has been automatically created in your root folder.

Creating a Data Connection

Page 27: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

Creating a New RecordSetGo to the Application Panel, click on “Bindings” tab, then follow the directions…

Naming convention:

rsDescriptive

Use “rsPeople”

Always testing the connection is a good habit to develop

Page 28: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

Insert Dynamic Data into Document

Page 29: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

Click on “Server Behavior” Tab and Note What you Find

Page 30: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

Repeating a Region with Multiple DataStep 1: Select table row <tr> as the region to repeat.

(Repeat Region is always linked to a specific HTML tag.)

Step 2: Select “Repeat Region” from Server Behaviors.

Page 31: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

Upload and Test the PageChoose to “include dependent files” (only necessary the first time you upload).

Reason: The “Connections” file needs uploaded too.

http://projects.coe.uga.edu/workshop/rieber/list.php

Your last name goes here

Page 32: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

Creating an Insert Page

Page 33: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

Create a New Document…

insert.php

Select from menubar…

Insert

Data Objects >

Insert Record >

Record Insertion Form Wizard

Page 34: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

Filling out the Dialog Box

Remove from list

Page 35: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

Form is Created… Feel free to modify

Page 36: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

Create “new_record_reply.html”

Click here to view all the records.

Page 37: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

Upload and Test

Page 38: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.
Page 39: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

Creating an Update/Delete Page

Page 40: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

Reminder: Get Extension 'Go To Detail Extension for PHP'

• Here’s the URL:

http://www.adobe.com/cfusion/exchange/index.cfm?event=extensionDetail&extid=627434

(Link is on workshop home page.)

Page 41: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

What If I Didn’t Get the Extension?

• Then you will have to enter the code manually:

Generic:

filename.php?recordID=<?php echo $row_recordsetName['fieldName']; ?>

Actual for the example to follow:

update.php?ID_people=<?php echo $row_rsPeople['ID_people']; ?>

Page 42: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

list.php: Add Text “update” to 4th Column

Page 43: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

Go to Detail Page

Highlight the text “update”, then choose to “Go to Detail Page” (in Server Behaviors)

Be sure that “ID_people” data will be passed as a URL parameter.

Page 44: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

Create “update.php” page

Click on “Bindings” tab, then choose to create a new recordset by clicking on + symbol and selecting “Recordset (Query).

The “filter” must match the data being passed from the previous slide:

Page 45: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

Record Update Form

Select from menubar…

Insert

Data Objects >

Update Record >

Record Update Form Wizard

Page 46: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

Complete Dialog Box

Remove from list

Page 47: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

Modify Form As You Wish

Page 48: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

Create the Reply page

update_record_reply.htm

Be sure to include a link back to “list.php”

Page 49: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

Upload and Test the Page

Page 50: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

Upload and Test the Page

Notice the data appended to the end of the URL

Page 51: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

Creating a User Login Page

Create a form. Then, create a 2 X 2 table in the form as shown below.

In the Property Inspector window…

Title this TextField “email”

Title this TextField “password”

Page 52: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

Creating a User Login PageClick somewhere inside the form,

then select the <form> tag.

In the Action field, enter this page title (we will create the page itself later).

Be sure to choose POST as the method.

The GET method will send the user’s email and password as part of the URL, which is a security risk. Upload the page.

Page 53: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

Creating the “update-account.php” Page

Insert a 2 X 1 table with messages as shown below in each row.

Page 54: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

Creating the “update-account.php” PageIn the Bindings tab, choose to create a new Recordset (Query):

Name the recordset “rsAccount” and select the connection:

Page 55: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

Creating the “update-account.php” PageClick on the “Advanced…” button…

The dialog box changes to give us access to the SQL programming…

Page 56: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

Creating the “update-account.php” PageEnter the following SQL code and add the variables – varEmail and varPassword - as shown, test the code for errors, then click “OK”:

Page 57: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

Creating the “update-account.php” Page1. Click somewhere in the first row, then click on the <tr> tag to choose that row. This selects the row as a “region”:

2. With this region selected, go to the Server Behaviors and choose:Show Region > Show Region If Recordset is Empty.

3. Choose the ‘rsAccount’ RecordSet, and click OK:

Page 58: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

Creating the “update-account.php” Page

Repeat the steps on the previous slide, except:Select the second rowChoose to “Show Region If RecordSet Is Not Empty

Upload the page.

Page 59: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

Test the Log-In Page

Page 60: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

Test the Log-In PageIf you log-in correctly, you should see this result…

If you log-in incorrectly, you should see this result…

Page 61: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

Use the “Record Update Form Wizard” to add an update form to the second table row

Select from menubar…

Insert

Data Objects >

Update Record >

Record Update Form Wizard

Upload the page and test the site.

Page 62: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

Maintaining “State” of a UserTwo Approaches

• Passing data via the URL from page to page– Exactly what we have been doing so far– Drawbacks

• Users can bookmark specific pages without logging in

• Savvy users can access accounts other than their own

• Creating a session variable– User’s browser must be set to allow “cookies”

Page 63: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

Session Variable

• A type of cookie

• Stores a particular piece of information temporarily on the client’s computer– The variable is deleted when the browser is

closed, or when there is inactivity for a set period of time.

• How and where to declare this variable?

Page 64: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

Where to Set a Session Variable

• Needs to be set after a verified log-in has occurred

• Recommendation– Add this variable in the “Show Region”

behavior

Page 65: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

1. Click here to highlight the “Show Region” behavior associated with a successful log-in.

2. Click here to view the code.

Page 66: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

We will add the code to create the session variable as the first line AFTER the “If-then” statement

ASP Example!

Page 67: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

<% Session ("People_ID") = rsAccount.Fields.Item("People_ID").Value %>

Name of the record set. Name of the variable we need from the record set.

ASP Example!

Page 68: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

Using Session Variables

• Create a new .asp page

• In the Bindings tab, create a new record set and use the Session variable as a filter:

Page 69: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

Other Useful Session Commands

• Setting a time limit (in minutes) for when the Session variable will expire if there is no activity:

• Creating a “Log Out” option that clears all session variables

<% Session.Abandon %>

<% Session.TimeOut = 300 %>

ASP Example!

Page 70: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

VB Script

ASP Example!

Page 71: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

In Simple English:

If “ready4feedback” equals “y”, then display

Otherwise, display

Useful VB Script Example

This “If-Then” statement checks the value of a particular field in a recordset and displays an appropriate graphic depending on its value.

<% If (rsIDA_course.Fields.Item("ready4feedback").Value) = "y" Then _ Response.Write("<img src='resources/yes.gif'>") _Else Response.Write("<img src='resources/no.gif'>") %>

ASP Example!

Page 72: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

Book Recommendations for Learning More

Page 73: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.
Page 74: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.
Page 75: Creating Dynamic Database-Driven Sites with Dreamweaver Lloyd Rieber Workshop Home Page:  ASP PHP JSP ColdFusion.

References• Bardzell, J., Flynn, B. (2007). Adobe Dreamweaver CS3

with ASP, ColdFusion, and PHP: Training from the Source. Adobe Press.

• Lowery, J. W. (2007). Dreamweaver CS3 Bible. Indianapolis, IN: Wiley Publishing.

• Meloni, J., & Telles, M. (2008). PHP 6 Fast & Easy Web Development. Boston: Course Technology.

• Mitchell, S., & Atkinson, J. (2000). Teach yourself Active Server Pages 3.0 in 21 days. Indianapolis, IN: SAMS.

• Ray, J. (2003). Teaching yourself Dreamweaver MX Application Development in 21 days. Indianapolis, IN: SAMS.