Server-Side Processing II

Slides:



Advertisements
Similar presentations
PHP II Interacting with Database Data. The whole idea of a database-driven website is to enable the content of the site to reside in a database, and to.
Advertisements

Server-Side vs. Client-Side Scripting Languages
ASP Tutorial. What is ASP? ASP (Active Server Pages) is a Microsoft technology that enables you to make dynamic and interactive web pages. –ASP usually.
PHP CSCE 330 February 6, 2003 Group Members: Antwan B. Phan George Hwang Luat Vu Programming Language Presentation.
Session 6 Server-side programming - ASP. An ASP page is an HTML page interspersed with server-side code. The.ASP extension instead of.HTM denotes server-side.
B.Sc. Multimedia ComputingMedia Technologies Database Technologies.
Creating Web Page Forms. Objectives Describe how Web forms can interact with a server-based program Insert a form into a Web page Create and format a.
Apache Tomcat Server – installation & use Server-side language-- use Java Server Pages Contrast Client-side languages HTML Forms Servers & Server-side.
Week 2 IBS 685. Static Page Architecture The user requests the page by typing a URL in a browser The Browser requests the page from the Web Server The.
By Morris Wright, Ryan Caplet, Bryan Chapman. Overview  Crawler-Based Search Engine (A script/bot that searches the web in a methodical, automated manner)
Multiple Tiers in Action
1 Foundations of Software Design Lecture 27: Java Database Programming Marti Hearst Fall 2002.
2440: 141 Web Site Administration Web Server-Side Programming Professor: Enoch E. Damson.
1 CS428 Web Engineering Lecture 18 Introduction (PHP - I)
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
1 Web Developer & Design Foundations with XHTML Chapter 6 Key Concepts.
1 Web Database Processing. Web Database Applications Static Report Publishing a report is prepared from a database application and exported to HTML DB.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Server- Side technologies Client-side vs. Server-side scripts PHP basic ASP.NET basic ColdFusion.
XP Tutorial 6New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Creating Web Page Forms Designing a Product Registration Form Tutorial.
1 Creating Web Forms in HTML Web forms collect information from customers Web forms include different control elements including: –Input boxes –Selection.
INFM 603: Information Technology and Organizational Context Jimmy Lin The iSchool University of Maryland Thursday, October 18, 2012 Session 7: PHP.
Server-side Scripting Powering the webs favourite services.
Basics of Web Databases With the advent of Web database technology, Web pages are no longer static, but dynamic with connection to a back-end database.
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.
Web Server Administration Chapter 7 Installing and Testing a Programming Environment.
Class 1Intro to Databases Goals of this class Understand the architecture behind web database applications Gain a basic understanding of what relational.
Tutorial 7 Creating Forms. Objectives Session 7.1 – Create an HTML form – Insert fields for text – Add labels for form elements – Create radio buttons.
Website Design Lecture 1. Outline Introduction to the module Outline of the Assessment Schedule Lecture Static XHTML, client side and server side Why.
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.
MySQL Databases & PHP Integration Using PHP to write data to, and retrieve data from, a MySQL database.
PHP and MySQL CS How Web Site Architectures Work  User’s browser sends HTTP request.  The request may be a form where the action is to call PHP.
Lecture Note 1: Getting Started With ASP.  Introduction to ASP  Introduction to ASP An ASP file can contain text, HTML tags and scripts. Scripts in.
CSC 2720 Building Web Applications Server-side Scripting with PHP.
Creating PHPs to Insert, Update, and Delete Data CS 320.
Introduction to PHP Advanced Database System Lab no.1.
Introduction to JavaScript CS101 Introduction to Computing.
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.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
ASP. ASP is a powerful tool for making dynamic and interactive Web pages An ASP file can contain text, HTML tags and scripts. Scripts in an ASP file are.
Database Connectivity and Server-Side Scripting Chapter 12.
1) PHP – Personal Home Page Scripting Language 2) JavaScript.
8 th Semester, Batch 2009 Department Of Computer Science SSUET.
Higher Computing Science Coding the Web: HTML, JavaScript, PHP and MySQL.
Web Design Terminology Unit 2 STEM. 1. Accessibility – a web page or site that address the users limitations or disabilities 2. Active server page (ASP)
XP Tutorial 6New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Creating Web Page Forms Designing a Product Registration Form Tutorial 6.
Internet/Web Databases
Introduction to Dynamic Web Programming
Section 6.3 Server-side Scripting
Introduction and Principles
Introduction to CodeIgniter (CI)
* Lecture # 7 Instructor: Rida Noor Department of Computer Science
PHP / MySQL Introduction
Intro to PHP & Variables
PHP Overview PHP: Hypertext Preprocessor Server-Side Scripting
Cookies BIS1523 – Lecture 23.
Database Driven Websites
HTML Forms and User Input
Web Systems Development (CSC-215)
IntroductionToPHP Static vs. Dynamic websites
Tutorial 6 PHP & MySQL Li Xu
Web Application Development Using PHP
Presentation transcript:

Server-Side Processing II 2. PHP PHP is a specialised scripting language designed to carry out sophisticated and flexible server-side processing. It uses a mixture of C and Perl style syntax. In makes dynamic web content generation possible. What’s this? 1

No, they use some form of dynamic content generation instead. If you look at major sites like infoseek or cnet or yahoo you will find that they have content which is changing on an hourly basis. Does this mean they have teams of HTML’ers frantically altering the .html pages to update content ? No, they use some form of dynamic content generation instead. This means that the content of the site is separated from the formatting information (the HTML). The content is stored in tables in a database. When the user requests a page, the server (a) retrieves the content from the DB (b) formats it as a HTML page (c) sends it to the user’s browser To update the content, the site owners update the database. No fiddling with HTML. So how is (b) and (c) accomplished?

So will ASP (Active Server Pages). We write a program which queries the database (using SQL commands) and constructs HTML pages on the fly from the results. PHP will do this for us. So will ASP (Active Server Pages). What would such a program look like? Firstly PHP code is embedded inside regular HTML files. Suppose we have created a database which is stored on the server and looks like this. The fields are called name and phone. Homer Simpson 234-7575 Bart Simpson 234-6655 Lisa Simpson 234-7777 Marge Simpson 234-6565 Maggie Simpson 234-6577

<html> <head> <title>Web Database Sample Index</title> </head> <body bgcolor=#ffffff> <h1>Data from Simpsons Table</h1> <? mysql_connect("localhost", "webuser", ""); $query = "SELECT name, phone FROM mytable"; $result = mysql_db_query("example", $query); if ($result) { echo "Found these entries in the database:<ul>"; while ($r = mysql_fetch_array($result)) { $name = $r["name"]; $phone = $r["phone"]; echo "<li>$name, $phone"; } echo "</ul>"; } else { echo "No data."; } mysql_free_result($result); ?> </body> </html>

Let’s have a look at this. <? Indicates to the server that the following code is PHP. Finish with ?>. In this example we are using a database system called MySQL. It’s a free version of something like SQL Server. mysql_connect("localhost", "webuser", ""); This established a connection with the database. $query = "SELECT name, phone FROM mytable"; Variables are preceded with $ symbols. So this sets up a string variable which corresponds to a standard database query. $result = mysql_db_query("example", $query); This executes the query and stores the result in $result. If there was a result we get the following: echo "Found these entries in the database:<ul>"; echo sends the contents of the string to the browser. If you send HTML tags then they will be understood as such.

Data from Simpson’s Table Homer Simpson, 234-7575 The while loop then repeatedly fetches rows from the database and stored the results in variables $name and $phone. It outputs them each time as: echo "<li>$name, $phone"; This simply creates a HTML list item with the data and sends it to the browser. The result will be a web page containing: Data from Simpson’s Table Homer Simpson, 234-7575 Bart Simpson, 234-6655 Lisa Simpson, 234-7777 Maggie Simpson, 234-6577 Marge Simpson, 234-6565

So we can update the content of the web page by simply updating the database. Even better we can combine this with forms by using code like the following. <html> <body bgcolor=#ffffff> <? if (isset($name) && isset($phone)) { mysql_connect("localhost", "webuser", ""); $query = "INSERT INTO mytable VALUES ('$name', '$phone')"; $result = mysql_db_query("example", $query); if ($result) { echo "<p>$name was added to the database</p>"; } } ?> <h1>Add an entry</h1> <form> Name: <input type=text name='name'><br> Phone: <input type=text name='phone'><br> <input type=submit> </form> </body> </html>

This links the form to the database in such a way that if values are entered into the form and the submit button pressed, the script is executed an SQL insert command invoked to add a new row to the DB. This means we can easily provide HTML pages to update web sites through a browser …… no knowledge of HTML required! We can issue any SQL commands we like from a PHP script e.g. commands to search the database and we can format the results in any way we like. Big advantage is that we only have to worry about compatibility at the server side. As long as it undertands PHP we’re in business. Great tutorial about this (where this lecture’s examples were taken from) at http://www.devshed.com/Server_Side/Administration/Database/

There are a myriad of other technologies out there for doing this kind of thing (e.g. Microsoft’s Active Server Pages (ASP, ColdFusion, MacroMedia’s drumbeat and so on ….). The combination of PHP and MySQL however is powerful, well-supported, flexible and free! The disadvantage of carrying out processing of any kind on the server is that you have to either (a) have control over your own server so that you can ensure the correct software is present or (b) rent space on someone else’s server which you know contains the correct software.