Creating Dynamic Web Pages Using PHP and MySQL CS 320.

Slides:



Advertisements
Similar presentations
PHP I.
Advertisements

PHP Hypertext Preprocessor Information Systems 337 Prof. Harry Plantinga.
Introduction to PHP MIS 3501, Fall 2014 Jeremy Shafer
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Web Database Programming Using PHP.
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.
IST 221 Internet Concepts and Applications Introduction to PHP.
Introduction to Web Database Processing
Creating WordPress Websites. Creating a site on your computer Local server Local WordPress installation Setting Up Dreamweaver.
Dynamic Web Pages. Web Programming  All our web pages so far have been static pages. 1. We create a web page 2. We upload it to the web server 3. People.
Apache Tomcat Server – installation & use Server-side language-- use Java Server Pages Contrast Client-side languages HTML Forms Servers & Server-side.
Introduction to Web Interface Technology (CSE2030)
Multiple Tiers in Action
Creating Database Tables CS 320. Review: Levels of data models 1. Conceptual: describes WHAT data the system contains 2. Logical: describes HOW the database.
PHP Scripts HTML Forms Two-tier Software Architecture PHP Tools.
2440: 141 Web Site Administration Web Server-Side Programming Professor: Enoch E. Damson.
1 CS428 Web Engineering Lecture 18 Introduction (PHP - I)
PHP By Dr. Syed Noman Hasany. PHP PHP was originally created by Rasmus Lerdorf in PHP stands for PHP: Hypertext Preprocessor (a recursive acronym).
8/17/2015CS346 PHP1 Module 1 Introduction to PHP.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
Server Side Scripting Norman White. Where do we do processing? Client side – Javascript (embed code in html) – Java applets (send java program to run.
August Chapter 1 - Essential PHP spring into PHP 5 by Steven Holzner Slides were developed by Jack Davis College of Information Science and Technology.
INTRODUCTION TO WEB DATABASE PROGRAMMING
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.
AIT 616 Fall 2002 PHP. AIT 616 Fall 2002 PHP  Special scripting language used to dynamically generate web documents  Open source – Free!!!  Performs.
MySQL in PHP – Page 1 of 17CSCI 2910 – Client/Server-Side Programming CSCI 2910 Client/Server-Side Programming Topic: MySQL in PHP Reading: Williams &
IDK0040 Võrgurakendused I harjutus 06: PHP: Introduction Deniss Kumlander.
INTERNET APPLICATION DEVELOPMENT For More visit:
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
NMED 3850 A Advanced Online Design January 26, 2010 V. Mahadevan.
Nael Alian Introduction to PHP
10/5/2015CS346 PHP1 Module 1 Introduction to PHP.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
NMED 3850 A Advanced Online Design January 12, 2010 V. Mahadevan.
Overview: 1. Discussion of the basic architecture of a web application. 2. Discussion of the relevance of using MySQL and PHP in a web application.
HTML, PHP, and MySQL: Putting It All Together. Making a Form Input tags Types: “text” “radio” “checkboxes” “submit”
Creating PHPs to Insert, Update, and Delete Data CS 320.
Just a Little PHP Programming PHP on the Server. Common Programming Language Features Comments Data Types Variable Declarations Expressions Flow of Control.
Intro to PHP IST2101. Review: HTML & Tags 2IST210.
Introduction to PHP Advanced Database System Lab no.1.
1 MSCS 237 Overview of web technologies (A specific type of distributed systems)
CSE 154 LECTURE 5: INTRO TO PHP. URLs and web servers usually when you type a URL in your browser: your computer looks up the.
ASP (Active Server Pages) by Bülent & Resul. Presentation Outline Introduction What is an ASP file? How does ASP work? What can ASP do? Differences Between.
Controlling Web Site Access Using Logins CS 320. Basic Approach HTML form a php page that collects the username and password  Sends them to second PHP.
David Lawrence 7/8/091Intro. to PHP -- David Lawrence.
הרצאה 4. עיבוד של דף אינטרנט דינמי מתוך Murach’s PHP and MySQL by Joel Murach and Ray Harris.  דף אינטרנט דינמי משתנה עפ " י הרצת קוד על השרת, יכול להשתנות.
Creating a simple database This shows you how to set up a database using PHPMyAdmin (installed with WAMP)
Web Design and Development. World Wide Web  World Wide Web (WWW or W3), collection of globally distributed text and multimedia documents and files 
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
IS2803 Developing Multimedia Applications for Business (Part 2) Lecture 2: Introduction to IS2803 Rob Gleasure
Higher Computing Science Coding the Web: HTML, JavaScript, PHP and MySQL.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Web Database Programming Using PHP.
1 PHP Intro PHP Introduction After this lecture, you should be able to: Know the fundamental concepts of Web Scripting Languages in general, PHP in particular.
COSC 2328 – Web Programming.  PHP is a server scripting language  It’s widely-used and free  It’s an alternative to Microsoft’s ASP and Ruby  PHP.
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
Web Page Designing With Dreamweaver MX\Session 1\1 of 9 Session 1 Introduction to PHP Hypertext Preprocessor - PHP.
PHP Overview. What is PHP Widely available scripting language Free Alternative to Microsoft’s ASP Runs on the Web Server; not in the browser Example:
IST 210: PHP Basics IST 210: Organization of Data IST2101.
1 Server Side scripting PHP. 2 What is PHP? PHP stands for PHP: Hypertext Preprocessor PHP is a server-side scripting language, like ASP PHP scripts are.
1 Chapter 1 INTRODUCTION TO WEB. 2 Objectives In this chapter, you will: Become familiar with the architecture of the World Wide Web Learn about communication.
PHP using MySQL Database for Web Development (part II)
Web Database Programming Using PHP
Introduction to Dynamic Web Programming
Web Database Programming Using PHP
PHP Overview PHP: Hypertext Preprocessor Server-Side Scripting
PHP.
Web DB Programming: PHP
Tutorial 6 PHP & MySQL Li Xu
Client-Server Model: Requesting a Web Page
Presentation transcript:

Creating Dynamic Web Pages Using PHP and MySQL CS 320

Review: Dynamic vs. Static Web Pages  Static Web page  Developer specifies contents when he/she creates the Web page  Contents do not change based on user inputs  Dynamic Web page  Content varies based on:  User inputs  Data retrieved from external sources such as databases

Review: Web/Database Architecture Network Web browser Web server 2.Request for Web page that requires database data 1.Request for Web page that requires database data 6. Web page HTML file downloaded to client 5. Web page HTML file containing database data downloaded to client Database 3.Runs a program that makes a data request 4. Data response

What is a PHP page? Text file with a.php extension Contains HTML tags and elements Also contains embedded PHP commands that the Web server processes to create dynamic content

Why use PHP? PHP uses a similar coding style to other server-side scripting languages (ASP, JSP, Cold Fusion)  If you know how to create a PHP, you won’t find it difficult to learn how to use one of these alternate technologies With a PHP, you can first create a static Web page, then add the commands for dynamic processing  Separates design and program commands (somewhat) Widely used server-side technology  Open source and free  Supports many databases

Running PHP on a Web Server Web server must support PHP processing You must have privileges to save pages in the Web server folder structure

CS 320 Web Development Environment Create PHPs using Dreamweaver Upload to the class Web server for testing  Map a drive to a specific folder  Save your files in a folder on the server  Test your PHPs using a specific URL

CS 320 Test Environment Map a drive to \\leela.cs.uwec.edu\CS320$ \\leela.cs.uwec.edu\CS320$ Save files to your folder in the Students folder URL for testing:  RUSERNAME/filename.php

Creating PHPs and PHP Syntax PHP commands are embedded within an HTML document  Document must be saved with a.php extension Place PHP script commands within delimiters:

How are PHP Commands Processed? Commands within the block are processed on the server before sending the page back to the user's browser  The code isn’t sent to the browser – only the results of the code  Users can’t View Source to see the code  You can’t open a PHP file directly in a browser to run the PHP commands (as you can do with JavaScript) A web server is needed to process PHP commands

General PHP Syntax Notes Every command line must end with ; Comment statements:  // single line  /* block of comments */ echo  Displays a dynamic value on the Web page Supports basic programming constructs:  Variables  If/then statements  Loops  Functions  Assumption: You have learned basic programming concepts in a previous course

Example PHP CS Hello World Hello World! Today's date is:

Using PHP Variables Variable names start with $ Data types include:  Booleans (true/false)  Integers  Floating point numbers  Text strings  Arrays  Objects PHP will make conversions as needed to make data type match the assigned value

Using PHP to Retrieve Data From a MySQL Database Steps:  Improve PHP's error messages 1.Connect to the MySQL server 2.Select the MySQL database 3.Send the query to MySQL and store the results 4.Retrieve the number of rows that were returned 5.Close the connection to MySQL 6.Display the results

Improving MySQL's Error Messages Add the following as the first line in all of your PHP pages:

Connecting to the server and selecting the database In PHPs, you need to use the central DB server  Web server can't access your local database <?php //Connect to the MySQL database mysql_connect("dario.cs.uwec.edu","CS320_Student","C4361$") or die("Could not connect to MySQL. The reported SQL error is: ". mysql_error()); //Specify the database mysql_select_db("CS320_Student") or die("Could not connect to the database. The reported SQL error is: ". mysql_error()); ?> Database serverUsernamePassword Database within the user schema

Specifying the query, storing the result, closing the connection: Notes: Use your local DB to test queries, then copy/paste them into your PHPs Don't use hard returns to format your queries! <?php //Steps to connect to the server and select the database //Specify the query $query = "SELECT prod_id, prod_desc, prod_cost, prod_price FROM candy_product"; //Store the result $result = mysql_query($query) or die("SQL Error: ". mysql_error(). " "); //Close the connection mysql_close(); ?>

Formatting queries on multiple lines: <?php //Connect to the MySQL database mysql_connect("dario.cs.uwec.edu","CS320_Student","C4361$") or die("Could not connect to MySQL. The reported SQL error is: ". mysql_error()); //Specify the database mysql_select_db("CS320_Student") or die("Could not connect to the database. The reported SQL error is: ". mysql_error()); //Specify the query $query = "SELECT prod_id, prod_desc, prod_cost, prod_price ". "FROM candy_product"; //Store the result $result = mysql_query($query) or die("SQL Error: ". mysql_error(). " "); ?> Concatenation operator

Displaying the Data Product ID Description Cost Price $ Variable storing a row of retrieved data Database field name