Go To Detail Extension for PHP
Download
Report
Transcript Go To Detail Extension for PHP
Creating Dynamic Database-Driven
Sites with Dreamweaver
ASP
PHP
JSP
ColdFusion
Lloyd Rieber
Workshop Home Page:
http://projects.coe.uga.edu/workshop/rieber/
Last updated on November 20, 2008
Recommended: Get and Install the Dreamweaver
Extension
'Go To Detail Extension for PHP'
• Here’s the URL:
http://www.adobe.com/cfusion/exchange/in
dex.cfm?event=extensionDetail&extid=627
434
(Link is on workshop home page.)
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
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
http://www.nowhereroad.com/instructionaldesign
Program Flowchart
list.php
update.php
insert.php
Update Record
Insert Record
update_record_reply.htm
new_record_reply.htm
Here are the files we will eventually create…
Client/Server Interaction for PHP Files
Server
Server locates
the PHP file on
the hard drive
and parses it,
removing all PHP
script and
replacing it with
HTML text
Client requests
PHP File
Client
Server returns HTML
text to client
Adapted from Mitchell & Atkinson (2000)
How Databases Work
A 15-Minute Primer
“Flat” Database Structure
Database
Record
Record
Record
Field
Field
Field
“Flat” Database Structure
Studio People
Lloyd
Ike
Greg
Database ID
Name
Course
Relational Database Structure
A Collection of Databases (tables) that connect (relate) to each other
People
John
People_ID
Name
Mary
Address
Jane
Email
Orders
Order1
People_ID
Order_ID
Order2
Book_Title
Order3
Price
Working Demonstration
(quickly)
Working with mySQL Databases
phpMyAdmin
http://projects.coe.uga.edu/pma
Getting Ready to Work with Dreamweaver
Step 1: Make a root folder
Step 2: Create a folder inside it
named:
yourLastname
Launch Dreamweaver
Step 3: Launch
Dreamweaver and
define a new site that
points to the root folder.
Remote Server Information
Password:
eu3$@93!
(this will be changed
within a few days)
Be sure to “Test” your
connection before
proceeding.
Notice that this server
needs a Secure FTP
connection.
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 serverside pathways, such as
“wwwroot”, from the
URL Prefix.
Creating a Simple Search/Results Page Set
Make a new file called “list.php”
Add a 2 X 4 table and format accordingly:
Creating a Data Connection
Go to the Application Panel, click on “Databases” tab, then follow the
directions…
Naming convention:
connDescriptive
Use “connLastName” (for reasons I’ll explain)
Creating a Data Connection
Notice that a folder titled
“Connections” has been
automatically created in
your root folder.
Creating a New RecordSet
Go to the Application Panel, click on “Bindings” tab, then follow the directions…
Always testing the
connection is a good
habit to develop
Naming convention:
rsDescriptive
Use “rsPeople”
Insert Dynamic Data into Document
Click on “Server Behavior” Tab and
Note What you Find
Repeating a Region with Multiple Data
Step 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.
Upload and Test the Page
Choose 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
Creating an Insert Page
Create a New Document…
insert.php
Select from menubar…
Insert
Data Objects >
Insert Record >
Record Insertion Form Wizard
Filling out the Dialog Box
Remove
from list
Form is Created… Feel free to modify
Create “new_record_reply.html”
Click here to view all the records.
Upload and Test
Creating an Update/Delete Page
Reminder: Get Extension
'Go To Detail Extension for PHP'
• Here’s the URL:
http://www.adobe.com/cfusion/exchange/in
dex.cfm?event=extensionDetail&extid=627
434
(Link is on workshop home page.)
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']; ?>
list.php: Add Text “update” to 4th Column
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.
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:
Record Update Form
Select from menubar…
Insert
Data Objects >
Update Record >
Record Update Form Wizard
Complete Dialog Box
Remove
from list
Modify Form As You Wish
Create the Reply page
update_record_reply.htm
Be sure to include a link
back to “list.php”
Upload and Test the Page
Upload and Test the Page
Notice the data appended to
the end of the URL
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”
Creating a User Login Page
Click somewhere inside the form,
then select the <form> tag.
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.
In the Action field, enter this page
title (we will create the page itself
later).
Upload the page.
Creating the “update-account.php” Page
Insert a 2 X 1 table with messages as shown below in each row.
Creating the “update-account.php” Page
In the Bindings tab, choose to create a
new Recordset (Query):
Name the recordset “rsAccount” and
select the connection:
Creating the “update-account.php” Page
Click on the “Advanced…” button…
The dialog box changes to give us
access to the SQL programming…
Creating the “update-account.php” Page
Enter the following SQL code and add the variables – varEmail and
varPassword - as shown, test the code for errors, then click “OK”:
Creating the “update-account.php” Page
1. 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:
Creating the “update-account.php” Page
Repeat the steps on the previous slide, except:
Select the second row
Choose to “Show Region If RecordSet Is Not Empty
Upload the page.
Test the Log-In Page
Test the Log-In Page
If you log-in correctly, you should see this result…
If you log-in incorrectly, you should see this result…
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.
Maintaining “State” of a User
Two 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”
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?
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
1. Click here to highlight the
“Show Region” behavior
associated with a successful login.
2. Click here to view the code.
ASP Example!
We will add the code to create the
session variable as the first line
AFTER the “If-then” statement
ASP Example!
<% Session ("People_ID") = rsAccount.Fields.Item("People_ID").Value %>
Name of the record set.
Name of the variable we
need from the record set.
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:
ASP Example!
Other Useful Session Commands
• Setting a time limit (in minutes) for when
the Session variable will expire if there is
no activity:
<% Session.TimeOut = 300 %>
• Creating a “Log Out” option that clears all
session variables
<% Session.Abandon %>
ASP Example!
VB Script
ASP Example!
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'>") %>
In Simple English:
If “ready4feedback” equals “y”, then display
Otherwise, display
Book Recommendations for Learning More
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.