© Neeraj Suri EU-NSF ICT March 2006
DEWSNet
Dependable Embedded Wired/Wireless Networks MUET Jamshoro
Creating Dynamic Database-Driven Sites
with Dreamweaver
Faisal Karim Shaikh
DEWSNet Group
Dependable Embedded Wired/Wireless Networks www.fkshaikh.com/dewsnet
PS: Some slides are taken from Lloyd Rieber
Creating Dynamic Database-Driven Sites 2
Agenda
Seeing/doing it: Building a small dynamic
“people” web site
List current people, add new person, update existing
person
Creating Dynamic Database-Driven Sites 3
Program Flowchart
list.php
insert.php update.php
update_record_reply.htm new_record_reply.htm
Update Record Insert Record
Creating Dynamic Database-Driven Sites 4
Client requests
PHP File
Client
Server
Server returns HTML
text to client
Server locates thePHP 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)
How Databases Work
A 15-Minute Primer
“Flat” Database Structure
Database
2
Creating Dynamic Database-Driven Sites 7
“Flat” Database Structure
MUET
People
Faisal
Jibran
Database
ID
Name
Password
Fayaz
Creating Dynamic Database-Driven Sites 8
Relational Database Structure
A Collection of Databases (tables) that connect (relate) to each other
People
Faisal
People_ID Name Password Jibran Fayaz
Orders
Order1
People_ID Order_ID Book_Title Price Order2 Order3
Creating Dynamic Database-Driven Sites 9
Working with mySQL Databases
phpMyAdmin
Creating Dynamic Database-Driven Sites 10
Creating Dynamic Database-Driven Sites 11 Step 1: Make a root folder
Step 2: Create a folder inside it named: yourLastname
Getting Ready to Work with Dreamweaver
Step 3: Launch Dreamweaver and define a new site that points to the root folder.
Creating Dynamic Database-Driven Sites 12
Creating Dynamic Database-Driven Sites 13
Make a new file called “list.php”
Add a 2 X 4 table and format accordingly:
Creating Dynamic Database-Driven Sites 14
Creating a Data Connection
Go to the Application Panel, click on “Databases” tab, then follow the directions…
Creating Dynamic Database-Driven Sites 15
Notice that a folder titled “Connections” has been automatically created in your root folder.
Creating a Data Connection
Creating Dynamic Database-Driven Sites 16
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
4
Creating Dynamic Database-Driven Sites 19
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.
Creating Dynamic Database-Driven Sites 20
Upload and Test the Page
Choose to “include dependent files” (only necessary the first time you upload). Reason: The “Connections” file needs uploaded too.
Creating Dynamic Database-Driven Sites 21
Creating an Insert Page
Creating Dynamic Database-Driven Sites 22
Create a New Document…
insert.php
Creating Dynamic Database-Driven Sites 23
Filling out the Dialog Box
Remove from list
Creating Dynamic Database-Driven Sites 24
Creating Dynamic Database-Driven Sites 25
Create “new_record_reply.html”
Creating Dynamic Database-Driven Sites 26
Upload and Test
Creating Dynamic Database-Driven Sites 27
Creating an Update/Delete Page
Creating Dynamic Database-Driven Sites 28
list.php: Add Text “update” to 3
rdColumn
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:
6
Creating Dynamic Database-Driven Sites 31
Record Update Form
Creating Dynamic Database-Driven Sites 32
Complete Dialog Box
Remove from list
Creating Dynamic Database-Driven Sites 33
Modify Form As You Wish
Creating Dynamic Database-Driven Sites 34
Create the Reply page
update_record_reply.php
Be sure to include a link
back to “list.php”
Creating Dynamic Database-Driven Sites 35
Upload and Test the Page
Creating Dynamic Database-Driven Sites 36
Creating a User Login Page
Creating Dynamic Database-Driven Sites 37
Creating a User Login Page
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.
Creating Dynamic Database-Driven Sites 38
Creating the “update-account.php” Page
Insert a 2 X 1 table with messages as shown below in each row.
Creating Dynamic Database-Driven Sites 39
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 Dynamic Database-Driven Sites 40
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 – varUname and varPass - as shown, test the code for errors, then click “OK”:
Creating the “update-account.php” Page
1. Select first row
2. With this region selected, go to the Server Behaviors and choose:
Show Region > Show Region If Recordset is Empty.
8
Creating Dynamic Database-Driven Sites 43
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.
Creating Dynamic Database-Driven Sites 44