Data-Driven Web Pages Stephen Rondeau 18 May 2009.

Slides:



Advertisements
Similar presentations
Connecting to Database 21 Feb Database Options Can use many different databases in conjunction with php. – MySql; MS Access; Oracle; etc etc Most.
Advertisements

Keys, Referential Integrity and PHP One to Many on the Web.
What is MySQL? MySQL is a relational database management system (A relational database stores data in separate tables rather than putting all the data.
B.Sc. Multimedia ComputingMedia Technologies Database Technologies.
DT228/3 Web Development Databases. Database Almost all web application on the net access a database e.g. shopping sites, message boards, search engines.
Database-driven Web Pages from Access Databases Stephen Rondeau TINST May 2009.
MySQL and PHP By Trevor Adams.
Chapter 7 Managing Data Sources. ASP.NET 2.0, Third Edition2.
Computer Science 101 Web Access to Databases Overview of Web Access to Databases.
2440: 141 Web Site Administration Web Server-Side Programming Professor: Enoch E. Damson.
From VS C# 2010 Programming, John Allwork 1 VS2010 C# Programming - DB intro 1 Topics – Database Relational - linked tables SQL ADO.NET objects Referencing.
PHP Programming. Topics Background and History of PHP Installation Comments in PHP Variables Conditions Loops Functions File Handling Database Handling.
1 Web Database Processing. Web Database Applications Static Report Publishing a report is prepared from a database application and exported to HTML DB.
Programming with php By: Seth Larson. A little bit about PHP  PHP stands for PHP:  Hypertext Preprocessor  PHP is a widely-used general-purpose server-side.
CHAPTER 9 DATABASE MANAGEMENT © Prepared By: Razif Razali.
Session 5: Working with MySQL iNET Academy Open Source Web Development.
Create an online booking system (login/registration)
CSE3310: Web training A JumpStart for Project.
Server-side Scripting Powering the webs favourite services.
4-1 INTERNET DATABASE CONNECTOR Colorado Technical University IT420 Tim Peterson.
Advanced Database Management System Lab no. 11. SQL Commands (for MySQL) –Update –Replace –Delete.
Chapter 7 PHP Interacts with Ms. Access (Open DataBase Connectivity (ODBC))
Copyright © 2003 Pearson Education, Inc. Slide 8-1 The Web Wizard’s Guide to PHP by David Lash.
PHP Programming with MySQL Slide 8-1 CHAPTER 8 Working with Databases and MySQL.
About Dynamic Sites (Front End / Back End Implementations) by Janssen & Associates Affordable Website Solutions for Individuals and Small Businesses.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
Mark Dixon Page 1 23 – Web applications: Writing data to Databases using PhP.
_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition1  Wiley and the.
Web Services Week 8 Aims: –Using web services as front ends to databases Objectives: –Review of relational databases –Connecting to and querying databases.
PHP meets MySQL.
Web Server Administration Chapter 7 Installing and Testing a Programming Environment.
Introduction to databases and SQL. What is a database?  A database is an organized way of holding together pieces of information  A database refers.
Class 1Intro to Databases Goals of this class Understand the architecture behind web database applications Gain a basic understanding of what relational.
SQL Queries Relational database and SQL MySQL LAMP SQL queries A MySQL Tutorial and applications Database Building Assignment.
15/10/20151 PHP & MySQL 'Slide materials are based on W3Schools PHP tutorial, 'PHP website 'MySQL website.
Introduction to MySQL Lab no. 10 Advance Database Management System.
PHP MySQL Introduction. MySQL is the most popular open-source database system. What is MySQL? MySQL is a database. The data in MySQL is stored in database.
Creating Dynamic Web Pages Using PHP and MySQL CS 320.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
NMED 3850 A Advanced Online Design January 12, 2010 V. Mahadevan.
SYST Web Technologies SYST Web Technologies Databases & MySQL.
Putting it all together Dynamic Data Base Access Norman White Stern School of Business.
Creating PHPs to Insert, Update, and Delete Data CS 320.
SQL Basic. What is SQL? SQL (pronounced "ess-que-el") stands for Structured Query Language. SQL is used to communicate with a database.
Web Server Administration Chapter 7 Installing and Testing a Programming Environment.
PHP getting data from a MySQL database. Replacing XML as data source with MySQL Previously we obtained the data about the training session from an XML.
NMD202 Web Scripting Week5. What we will cover today PHP & MySQL Displaying Dynamic Pages Exercises Modifying Data PHP Exercises Assignment 1.
Microsoft FrontPage 2003 Illustrated Complete Integrating a Database with a Web Site.
CITA 310 Section 7 Installing and Testing a Programming Environment (Textbook Chapter 7)
MySQL. Is a SQL (Structured Query Language) database server. Can be accessed using PHP with embedded SQL Queries Supports Large DB’s, 60,000 tables with.
Class 1Intro to Databases Goals of this class Understand the architecture behind web database applications Gain a basic understanding of what relational.
1) PHP – Personal Home Page Scripting Language 2) JavaScript.
ECMM6018 Enterprise Networking For Electronic Commerce Tutorial 6 CGI/Perl and databases.
Higher Computing Science Coding the Web: HTML, JavaScript, PHP and MySQL.
MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Sravanthi Lakkimsety Mar 14,2016.
CS320 Web and Internet Programming SQL and MySQL Chengyu Sun California State University, Los Angeles.
Programming for the Web MySQL Command Line Using PHP with MySQL Dónal Mulligan BSc MA
1 Section 1 - Introduction to SQL u SQL is an abbreviation for Structured Query Language. u It is generally pronounced “Sequel” u SQL is a unified language.
Introduction to Dynamic Web Programming
CS320 Web and Internet Programming SQL and MySQL
Website Development Basics with PHP MySQL
PHP Overview PHP: Hypertext Preprocessor Server-Side Scripting
ISC440: Web Programming 2 Server-side Scripting PHP 3
Web Systems Development (CSC-215)
Server-Side Processing II
CS3220 Web and Internet Programming SQL and MySQL
CS3220 Web and Internet Programming SQL and MySQL
Presentation transcript:

Data-Driven Web Pages Stephen Rondeau 18 May 2009

Agenda Problem Statement Static vs. Dynamic Information Browsers and Web Servers Quick Database Tutorial Web and Database Servers How to Access a Database from Web Page

Problem Statement “Put x on the web” x could be employee data, songs, order info, etc. Questions to ask: Why? What information – all or partial? What can be done? Who can do what?

Sample Data In File

Static vs. Dynamic Information Could put information directly in web pagedirectly in web page Can be formatted to look better Someone who knows about web pages can update Okay solution if data doesn't change more than once per day and entire information is desired Could put information into a file that page referencesfile that page references Link to a text file Anyone could update – no knowledge of web Easier to maintain, but doesn't look great Information is static cannot be changed except by updating entire file What if person who updates can't do it?

Web Page with Data 101 John Smith 102 Jane Doe 103 Mary Adams 104 Tim O'Brian

Static vs. Dynamic Information Dynamic information: data can change often Web page displays a snapshot of current data Someone is adding, changing or deleting data If new or changed data comes from the web, how does it get there from browser?

Browsers and Web Servers Web Server Browser

Browsers and Web Servers Web Server Browser GET index.html

Browsers and Web Servers Web Server Browser index.html

Browsers and Web Servers Web Server Browser Last Name: First Name: <input type="submit" name="submit" value="Submit"> See form form.html lu.php form.html GET form.html form.html

Browsers and Web Servers Web Server Browser POST lu.php?ln=Smith&fn=Joe Last Name: First Name: <input type="submit" name="submit" value="Submit"> See form form.html lu.php lname= fname=<?php echo $_POST["fn"]; ? form.html lu.php HTML from lu.php

Quick Database Tutorial Evolved from simple files  programs supporting searching files for criteria needed to be changed for each new set of data  updating and deleting was difficult and inefficient Generalized, consistent way to structure data Data is efficiently stored and can be searched Database is collection of tables and other info table consists of rows of related columns of data  each column is named and typed other info includes user accounts and passwords, views, indices, procedures, etc.

Sample Data in Table

Quick Database Tutorial Data usually accessed via SQL SQL is Structured Query Language  INSERT puts data in table  SELECT retrieves data that matches criteria  UPDATE changes data in table  DELETE removes data from table Examples insert into employees(id, firstname, lastname) values(105,'Lee','O''Leary') select * from employees where lastname='Smith'

Quick Database Tutorial DBMS: Database Management System Common DBMSes:  Oracle, IBM DB2, Microsoft SQL Server Robust, heavy-duty, complex, large, server-based, expensive  MySQL, Firebird Robust, medium-duty, understandable, small, server-based, free  Microsoft Access Adequate, light-duty, very understandable, medium, local, affordable De-emphasizes SQL, but it's there Simple export to SQL Server

Web and Database Servers Browser Web Server Database Server OR Browser Web and Database Server

How to Access DB from Web Use PHP and ODBC PHP: Perl Hypertext Processor  Scripting language for dynamic web pages  Embedded in HTML:  Must be installed and configured on web server ODBC: Open DataBase Connectivity  Standardized way to access DBMSes  Independent of programming language, DBMS, OS  Can switch to different DBMSes without changing code

How to Access DB from Web PHP ODBC functions: must be installed  odbc_connect(): connect to DB  odbc_exec(): execute SQL statement  odbc_fetch_row(): get a returned row from odbc_exec()  odbc_result(): pick out column data from row  odbc_close(): cleanup and close DB connection

How to Access DB from Web Outline of tasks: Connect to DB and save connection “handle”  Use odbc_connect() Do something with DB via connection handle  Pass a SQL statement to odbc_exec()  Usually loop over returned rows with odbc_fetch_row() Extract data from rows using odbc_result() Close DB connection  Use odbc_close()

Connecting to Database Using “housing” database Access database exported to SQL Server Will use tblEmployees Save as file "connect_db.php": <?php $db = odbc_connect("dsn", "user", "pw") or die "not connected"; print "connected "; ?> – _test.php _test.php dsn is reference to database or "data set name" user is database user id; pw is password for that user id

Displaying a Table Copy "connect_db.php" to "show.php" In place of print line: $stmt = "select * from tblEmployees"; $result = odbc_exec($db, $stmt); if ($result == FALSE) die("Problem with $stmt"); while (odbc_fetch_row($result)) { print odbc_result($result, "LastName"). ", ". odbc_result($result, "FirstName"); print " "; }

Searching a Table Search table for last name Last name is supplied by user via browser Two part process: Part 1: accept search "key" from the user Part 2: perform the search using the key Part 1: Asking the user is HTML save as "get_key.php" Last Name:

Searching a Table, Part 2 For example, let's say the key value is 'Smith' Part 2: performing the search is PHP Any user information in $_POST[ ]  e.g., $_POST[“key”]  Value is Smith Copy "show.php" to "search.php" and modify as follows $key = str_replace("'", "''", $_POST["key"]); $stmt = "select * from tblEmployees where LastName = '$key'"; First line gets key passed from "get_key.php", replacing each single quote with two single quotes Second line uses SQL to search table for match

Adding/Changing/Deleting Table Contents Standard form (table display): Add a record Change/Delete record 1… Change/Delete record 2… Change/Delete record 3… etc. "Add a record" is a link to add.php, which asks user for field values of record "Change" is a link to change.php with the record id supplied "Delete" is a link to del.php with the record id supplied

HTML for Add/Change/Delete HTML: Add a record Change / Delete … add.php doesn't require an id: new record change.php and del.php pass the id value in the query string; here the id is 24, e.g.

Add Process Like searching, two parts: Part 1: get values from user for fields of record Part 2: insert the record in the table with id add.php: Last Name: First Name:

Add Process, Part 2 add_rec.php (just the important pieces): $lastname = str_replace("'","''",$_POST["lastname"]); $firstname = str_replace("'","''",$_POST["firstname"]); $stmt = "select max(employeenumber)+1 from tblEmployees"; $result = odbc_exec($db, $stmt); $new_id = odbc_result($result, 1); $stmt = "insert into tblEmployees(employeenumber, lastname, firstname) values($new_id, '$lastname', '$firstname')"; $result = odbc_exec($db, $stmt); if ($result == FALSE) die("Could not insert $stmt");

Change Process Three parts: Part 1: get values from table Part 2: let user change field values of record Part 3: update the record using id and other values

Change Process, Part 1 change.php (first part): <?php include 'connect_db.php'; $id = $_GET["id"]; $stmt = "select * from tblEmployees where employeenumber=$id"; $result = odbc_exec($db, $stmt); if ($result == FALSE) die("Could not find $id: $stmt"); $lastname = odbc_result($result, "LastName"); $firstname = odbc_result($result, "FirstName"); odbc_close($db); ?>

Change Process, Part 2 change.php (second part): <input type="hidden" name="id" value=" "> Last Name: <input type="text" name="lastname" value=" "> First Name: <input type="text" name="firstname" value=" ">

Change Process, Part 3 change_rec.php (just the important pieces): $id = $_POST["id"]; $lastname = str_replace("'", "''", $_POST["lastname"]); $firstname = str_replace("'", "''", $_POST["firstname"]); $stmt = "update tblEmployees set lastname='$lastname', firstname='$firstname' where employeenumber=$id"; $result = odbc_exec($db, $stmt); if ($result == FALSE) die("Could not update: $stmt");

Delete Process Could be simple – delete immediately via del.php (just the important pieces): $id = $_GET["id"]; $stmt = "delete from tblEmployees where employeenumber=$id"; $result = odbc_exec($db, $stmt); But deleting immediately doesn't allow for user mistake – should confirm with the user  search for info associated with id (e.g., lastname and firstname)  display info to user and ask for permission to delete, then delete as above if okay  how to do the confirmation is left as an exercise for the reader

References Documentation (includes PHP source) Web Page Examples