CS 174: Web Programming August 31 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak www.cs.sjsu.edu/~mak.

Slides:



Advertisements
Similar presentations
CS 174: Web Programming January 27 Class Meeting
Advertisements

Tutorial 6 Working with Web Forms
Tutorial 6 Working with Web Forms. XP Objectives Explore how Web forms interact with Web servers Create form elements Create field sets and legends Create.
Computer Science 101 Web Access to Databases Overview of Web Access to Databases.
Dynamic Web site With PHP and MySQL. MySQL The combination of MySQL database and PHP scripting language is optimum for building dynamic websites. MySQL.
CS 160: Software Engineering August 27 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
Chapter 9 Collecting Data with Forms. A form on a web page consists of form objects such as text boxes or radio buttons into which users type information.
Advance Database Management Systems Lab no. 5 PHP Web Pages.
Web forms in PHP Forms Recap  Way of allowing user interaction  Allows users to input data that can then be processed by a program / stored in a back-end.
Application Development Description and exemplification of server-side scripting language for server connection, database selection, execution of SQL queries.
Reading Data in Web Pages tMyn1 Reading Data in Web Pages A very common application of PHP is to have an HTML form gather information from a website's.
1 CS 3870/CS 5870 Static and Dynamic Web Pages ASP.NET and IIS.
XP Tutorial 6New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Creating Web Page Forms Designing a Product Registration Form Tutorial.
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
1 HTML and CGI Scripting CSC8304 – Computing Environments for Bioinformatics - Lecture 10.
Create an online booking system (login/registration)
1 CS 3870/CS 5870 Static and Dynamic Web Pages ASP.NET and IIS.
Server-side Scripting Powering the webs favourite services.
Web Programming: Client/Server Applications Server sends the web pages to the client. –built into Visual Studio for development purposes Client displays.
Python CGI programming
CSC 2720 Building Web Applications HTML Forms. Introduction  HTML forms are used to collect user input.  The collected input is typically sent to a.
CS 174: Web Programming September 23 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
Tutorial 7 Creating Forms. Objectives Session 7.1 – Create an HTML form – Insert fields for text – Add labels for form elements – Create radio buttons.
Creating Dynamic Web Pages Using PHP and MySQL CS 320.
School of Computing and Information Systems CS 371 Web Application Programming PHP – Forms, Cookies, Sessions and Database.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
NMED 3850 A Advanced Online Design January 12, 2010 V. Mahadevan.
Chapter 8 Collecting Data with Forms. Chapter 8 Lessons Introduction 1.Plan and create a form 2.Edit and format a form 3.Work with form objects 4.Test.
Website Development with PHP and MySQL Saving Data.
1 Welcome to CSC 301 Web Programming Charles Frank.
HTML Forms.
LOGO FORMs in HTML CHAPTER 5 Eastern Mediterranean University School of Computing and Technology Department of Information Technology ITEC229 Client-Side.
1 © Netskills Quality Internet Training, University of Newcastle HTML Forms © Netskills, Quality Internet Training, University of Newcastle Netskills is.
XHTML & Forms. PHP and the WWW PHP and HTML forms – Forms are the main way users can interact with your PHP scrip Typical usage of the form tag in HTML.
CS 174: Web Programming September 2 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
Tutorial 6 Working with Web Forms. XP Objectives Explore how Web forms interact with Web servers Create form elements Create field sets and legends Create.
Tutorial 6 Working with Web Forms. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Explore how Web forms interact with.
Creating Web Page Forms. Introducing Web Forms Web forms collect information from users Web forms include different control elements including: –Input.
Computational Boot Camp HTML Mike Schaffer. 8/23/2002 (MES) HTML What is HTML? HTML stands for HyperText Markup Language HTML is the language for publishing.
Copyright © Terry Felke-Morris WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5 7 TH EDITION Chapter 9 Key Concepts 1 Copyright © Terry Felke-Morris.
Web Architecture Introduction
CS 174: Web Programming September 28 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
CMPE 226 Database Systems September 2 Class Meeting Department of Computer Engineering San Jose State University Fall 2015 Instructor: Ron Mak
CS 174: Web Programming October 14 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
Creating a simple database This shows you how to set up a database using PHPMyAdmin (installed with WAMP)
©SoftMooreSlide 1 Introduction to HTML: Forms ©SoftMooreSlide 2 Forms Forms provide a simple mechanism for collecting user data and submitting it to.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Tutorial 6 Working with Web Forms. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Explore how Web forms interact with.
Unit 1 – Web Concepts Instructor: Brent Presley.
Servers- Apache Tomcat Server Server-side scripts- Java Server Pages.
Higher Computing Science Coding the Web: HTML, JavaScript, PHP and MySQL.
CS 174: Web Programming November 2 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
Internet & World Wide Web How to Program, 5/e Copyright © Pearson, Inc All Rights Reserved.
CS 160 and CMPE/SE 131 Software Engineering February 11 Class Meeting Department of Computer Science Department of Computer Engineering San José State.
Session 11: Cookies, Sessions ans Security iNET Academy Open Source Web Development.
CMPE 226 Database Systems April 19 Class Meeting Department of Computer Engineering San Jose State University Spring 2016 Instructor: Ron Mak
HTML III (Forms) Robin Burke ECT 270. Outline Where we are in this class Web applications HTML Forms Break Forms lab.
CMPE 226 Database Systems February 8 Class Meeting Department of Computer Engineering San Jose State University Spring 2016 Instructor: Ron Mak
Lesson 5 Introduction to HTML Forms. Lesson 5 Forms A form is an area that can contain form elements. Form elements are elements that allow the user to.
HTML Structure II (Form) WEEK 2.2. Contents Table Form.
Unit 4 Working with data. Form Element HTML forms are used to pass data to a server. A form can contain input elements like text fields, checkboxes, radio-buttons,
FORMS Explained By: Jasdeep Kaur. Lecturer, Department of Computer Application, PGG.C.G., Sector: 42, Chandigarh.
University of Kansas Department of Electrical Engineering and Computer Science Dr. Susan Gauch April 21, 2005 I T T C Introduction to Web Technologies.
XP Tutorial 6New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Creating Web Page Forms Designing a Product Registration Form Tutorial 6.
CMPE 280 Web UI Design and Development August 29 Class Meeting
Introduction to Dynamic Web Programming
Web Design and Development
Unit I: Collecting Data with Forms
CS 174: Server-Side Web Programming February 14 Class Meeting
Presentation transcript:

CS 174: Web Programming August 31 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak

Computer Science Dept. Spring 2015: January 29 CS 174: Web Programming © R. Mak Client-Server Web Apps 2 Client Side Web Browser Chrome Firefox Safari Microsoft IE Server Side Web Server Apache + PHP HTTP request HTTP response  HTTP request User’s form data  HTTP response Dynamically generated HTML page Don’t be confused because for now, both the client side (your browser) and the server side (the Apache web server) are running on the same computer (your laptop).

Computer Science Dept. Spring 2015: January 29 CS 174: Web Programming © R. Mak XAMPP Control Panel  Use the XAMPP control panel to start or stop: Apache Web Server MySQL Database Server FTP server 3

Computer Science Dept. Spring 2015: January 29 CS 174: Web Programming © R. Mak XAMPP Directory Structure 4 Folder htdocs is the root of all the web pages on your web server. Some web servers name the root folder public_html.

Computer Science Dept. Spring 2015: January 29 CS 174: Web Programming © R. Mak Serving Web Pages  The Apache web server serves web pages. Displayed on the client side by web browsers. Web pages can be static or dynamic.  Static web pages:.html HTML files that the web server reads from disk. A static page always displays the same content.  Dynamic web pages:.php Generated by PHP code running on the server. Contains dynamic content. 5

Computer Science Dept. Spring 2015: January 29 CS 174: Web Programming © R. Mak Form Data  A user can input data into an HTML form displayed on a client-side web browser.  When the user presses a Submit button, the browser sends to form data to a specified PHP program running on the web server.  The PHP program can use the form data to Query the back-end database. Generate a new HTML page to send to the user’s client-side web browser. 6

Computer Science Dept. Spring 2015: January 29 CS 174: Web Programming © R. Mak Ways to Send Form Data  A browser sends form data to a PHP file on the server when the user presses the submit button. The action attribute of the tab. Two methods to send form data: get and post. 7

Computer Science Dept. Spring 2015: January 29 CS 174: Web Programming © R. Mak Ways to Send Form Data, cont’d  Get method The form data is appended to the target URL. Good for small amounts of data. The data is visible:  Post method The data is sent via environment variables. Good for larger amounts of data. Slightly more secure than the get method. 8

Computer Science Dept. Spring 2015: January 29 CS 174: Web Programming © R. Mak Three-Tier Web Application Architecture 9 Client-side web browser Server-side web server (.html.php images, etc.) Form data Back-end database server (MySQL) Queries Data Static (.html) or dynamically generated (.php) web pages

Computer Science Dept. Spring 2015: January 29 CS 174: Web Programming © R. Mak Text Input: HTML Page 10 <form action="text.php" method="get"> User input First name: Last name: forms/text.html

Computer Science Dept. Spring 2015: January 29 CS 174: Web Programming © R. Mak Text Input: PHP Code 11 Text Greeting <?php $first = filter_input(INPUT_GET, "firstName"); print " Hello, $first! "; ?> forms/text.php

Computer Science Dept. Spring 2015: January 29 CS 174: Web Programming © R. Mak Checkbox Input: HTML Page 12 <form action="checkbox.php" method="post">... Any formatting? <input type="checkbox" name="strong" value="strong" /> Strong! <input type="checkbox" name="em" value="em" /> Emphasized!... forms/checkbox.html

Computer Science Dept. Spring 2015: January 29 CS 174: Web Programming © R. Mak Checkbox Input: PHP Code 13 <?php $first = filter_input(INPUT_POST, "firstName"); $output = "Hello, $first!"; if (filter_has_var(INPUT_POST, "strong")) { $output = " $output "; } if (filter_has_var(INPUT_POST, "em")) { $output = " $output "; } print $output; ?> forms/checkbox.php

Computer Science Dept. Spring 2015: January 29 CS 174: Web Programming © R. Mak Radio Button Input: HTML Page 14 <form action="radio.php" method="post">... Direction> <input type="radio" name="direction" value="coming" checked /> Coming <input type="radio" name="direction" value="going" /> Going... Every radio button in the same group must have the same name (e.g., direction ). forms/radio.html

Computer Science Dept. Spring 2015: January 29 CS 174: Web Programming © R. Mak Radio Button Input: PHP Code 15 <?php $first = filter_input(INPUT_POST, "firstName"); $direction = filter_input(INPUT_POST, "direction"); if ($direction == "coming") { $output = "Hello"; } else if ($direction == "going") { $output = "Good-bye"; } else { $output = "You are SO confused"; } $output = $output.", $first!";... print $output; ?> forms/radio.php

Computer Science Dept. Spring 2015: January 29 CS 174: Web Programming © R. Mak Select List Input: HTML Page 16 <form action="select.php" method="post">... Language? English Français Deutsch forms/select.html

Computer Science Dept. Spring 2015: January 29 CS 174: Web Programming © R. Mak Select List Input: PHP Code 17 <?php $first = filter_input(INPUT_POST, "firstName"); $direction = filter_input(INPUT_POST, "direction"); $language = filter_input(INPUT_POST, "language"); $error = "You are SO confused"; if ($direction == "coming") { switch ($language) { case "english": $output = "Hello"; break; case "french": $output = "Bonjour"; break; case "german": $output = "Guten tag"; break; default: $output = $error; } } else if ($direction == "going") { switch ($language) { case "english": $output = "Good-bye"; break; case "french": $output = "Au revoir"; break; case "german": $output = "Auf wiedersehen"; break; default: $output = $error; } } else { $output = $error; }... ?> forms/select.php

Computer Science Dept. Spring 2015: January 29 CS 174: Web Programming © R. Mak Start the MySQL Database Server 18

Computer Science Dept. Spring 2015: January 29 CS 174: Web Programming © R. Mak XAMPP Home Page 19 phpMyAdmin is a PHP-based GUI interface to the MySQL database server.

Computer Science Dept. Spring 2015: January 29 CS 174: Web Programming © R. Mak phpMyAdmin Home Page 20

Computer Science Dept. Spring 2015: January 29 CS 174: Web Programming © R. Mak Database Server Root Password  By default, there is no root password.  Set the root password using phpMyAdmin.  Go to the Users tab.  Edit the root user to change its password. 21

Computer Science Dept. Spring 2015: January 29 CS 174: Web Programming © R. Mak Database Server Root Password, cont’d 22

Computer Science Dept. Spring 2015: January 29 CS 174: Web Programming © R. Mak Enable phpMyAdmin to Connect  phpMyAdmin connects to the MySQL database server as the root user.  Now you must tell phpMyAdmin what the new root password is.  Edit the configuration file XAMPP/xamppfiles/phpmyadmin/config.inc.php Edit the line $cfg['Servers'][$i]['password'] = ' root password '; 23

Computer Science Dept. Spring 2015: January 29 CS 174: Web Programming © R. Mak Add a New Database User  Name the user after yourself or your team. Click “Add user” on the Users tab. Use “localhost” for the host.  Tick the checkbox to create a database with the same name. 24

Computer Science Dept. Spring 2015: January 29 CS 174: Web Programming © R. Mak Create a Table in the New Database 25

Computer Science Dept. Spring 2015: January 29 CS 174: Web Programming © R. Mak Insert Data into the Table 26

Computer Science Dept. Spring 2015: January 29 CS 174: Web Programming © R. Mak Browse the Table Contents 27

Computer Science Dept. Spring 2015: January 29 CS 174: Web Programming © R. Mak MySQL Command Line Interface 28 ~: /Applications/XAMPP/xamppfiles/bin/mysql -u supercoders -p Enter password: mysql> show databases; | Database | | information_schema | | supercoders | rows in set (0.00 sec) mysql> use supercoders Database changed mysql> show tables; | Tables_in_supercoders | | people | row in set (0.00 sec)

Computer Science Dept. Spring 2015: January 29 CS 174: Web Programming © R. Mak MySQL Command Line Interface, cont’d 29 mysql> select * from people; | id | first | last | gender | salary | | 101 | John | Adams | M | | | 102 | Mary | Smith | F | | | 105 | Helen | Troy | F | | | 110 | Albert | Jones | M | | rows in set (0.00 sec) mysql> select * from people -> where first = 'Helen' -> and last = 'Troy'; | id | first | last | gender | salary | | 105 | Helen | Troy | F | | row in set (0.00 sec) mysql>

Computer Science Dept. Spring 2015: January 29 CS 174: Web Programming © R. Mak Simple End-to-End Web Application!  Client side An HTML form to submit a person’s first and last names.  Server side PHP code that uses the first and last names to query the people table in the back end database. Dynamically generate a new web page containing a table of the query results.  Back end A database table containing people data. 30 Demo

Computer Science Dept. Spring 2015: January 29 CS 174: Web Programming © R. Mak Default Web Page: index.html 31 <form action="queryDB.php" method="get"> User input First name: Last name: people/index.html

Computer Science Dept. Spring 2015: January 29 CS 174: Web Programming © R. Mak PHP Page: queryDB.php 32 Query Results <?php $first = filter_input(INPUT_GET, "firstName"); $last = filter_input(INPUT_GET, "lastName"); try { // Connect to the database. $con = new PDO("mysql:host=localhost;dbname=supercoders", "supercoders", "sesame"); $con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);... } catch(PDOException $ex) { echo 'ERROR: '.$ex->getMessage(); } ?> people/queryDB.php

Computer Science Dept. Spring 2015: January 29 CS 174: Web Programming © R. Mak PHP Page: queryDB.php, cont’d 33 try {... $query = "SELECT * FROM people"; // We're going to construct an HTML table. print " \n"; // Fetch the database field names. $result = $con->query($query); $row = $result->fetch(PDO::FETCH_ASSOC); // Construct the header row of the HTML table. print " \n"; foreach ($row as $field => $value) { print " $field \n"; } print " \n";... } people/queryDB.html

Computer Science Dept. Spring 2015: January 29 CS 174: Web Programming © R. Mak PHP Page: queryDB.php, cont’d 34 try {... // Constrain the query if we got first and last names. if ((strlen($first) > 0) && (strlen($last) > 0)) { $query = "SELECT * FROM people ". "WHERE first = '$first' ". "AND last = '$last'"; } // Fetch the matching database table rows. $data = $con->query($query); $data->setFetchMode(PDO::FETCH_ASSOC);... } people/queryDB.html

Computer Science Dept. Spring 2015: January 29 CS 174: Web Programming © R. Mak PHP Page: queryDB.php, cont’d 35 try {... // Construct the HTML table row by row. foreach ($data as $row) { print " \n"; foreach ($row as $name => $value) { print " $value \n"; } print " \n"; } print ” \n";... } people/queryDB.html

Computer Science Dept. Spring 2015: January 29 CS 174: Web Programming © R. Mak Assignment #1  Construct a single MySQL database table that contains some data. Your choice of fields and data values.  Create an HTML page containing various types of input (text, checkboxes, radio buttons, etc.).  Create a PHP page that makes different queries of the database table based on the form data.  Dynamically generate a web page that displays the query results. 36

Computer Science Dept. Spring 2015: January 29 CS 174: Web Programming © R. Mak Assignment #1, cont’d  Make screen shots of your web pages.  Create a “dump” of your database with the mysqldump command located in the XAMPP bin directory: Note: No space between –p and the password. Example: The output file create.sql will allow the graders to recreate your database table. 37 mysqldump –u username –p password dbname > create.sql mysqldump -u supercoders -psesame supercoders > create.sql

Computer Science Dept. Spring 2015: January 29 CS 174: Web Programming © R. Mak Assignment #1, cont’d  Create a zip file named after your team (e.g., supercoders.zip ) containing: Your.html and.php files. Output from the mysqldump command. Screen shots of your web pages.  to Subject line: CS 174- section Assignment #1 team name CC all team members. 38

Computer Science Dept. Spring 2015: January 29 CS 174: Web Programming © R. Mak Assignment #1, cont’d  This is a team assignment. One submission per team. Each team member receives the same score.  Due Tuesday, Sept. 8 at 11:59 PM. 39