Sending data, forms and variables Please use speaker notes for additional information!

Slides:



Advertisements
Similar presentations
Social Web Design 1 Darby Chang Social Web Design.
Advertisements

Adding Dynamic Content to your Web Site
Introduction to PHP MIS 3501, Fall 2014 Jeremy Shafer
Introduction to Flowcharting
Introduction to Flowcharting A Supplement to Starting Out with C++, 4th Edition by Tony Gaddis Published by Addison-Wesley.
Chapter 31 Basic Form-Processing Techniques JavaServer Pages By Xue Bai.
A simple PHP application We are going to develop a simple PHP application with a Web interface. The user enters two numbers and the application returns.
CGI programming in Perl Learning Objectives: 1. To understand how a CGI program works in Perl and how to make it runnable in web browsers 2. To learn how.
Python and Web Programming
Guide To UNIX Using Linux Third Edition
(C)opyright 2003 Scott/Jones Publishers Introduction to Flowcharting A Supplement to Starting Out with C++, 4th Edition by Tony Gaddis Scott/Jones Publishers.
CGI Programming: Part 1. What is CGI? CGI = Common Gateway Interface Provides a standardized way for web browsers to: –Call programs on a server. –Pass.
DBM Databases Please use speaker notes for additional information!
2440: 141 Web Site Administration Web Server-Side Programming Professor: Enoch E. Damson.
Perl/cgi and an Access Database Please use speaker notes for additional information!
CGI Common Gateway Interface. CGI is the scheme to interface other programs to the Web Server.
JAVASCRIPT HOW TO PROGRAM -2 DR. JOHN P. ABRAHAM UTPA.
Chapter 9 Using Perl for CGI Programming. Computation is required to support sophisticated web applications Computation can be done by the server or the.
NETWORK CENTRIC COMPUTING (With included EMBEDDED SYSTEMS)
Introduction to PHP and Server Side Technology. Slide 2 PHP History Created in 1995 PHP 5.0 is the current version It’s been around since 2004.
Lab Assignment 7 | Web Forms and Manipulating Strings Interactive Features Added In this assignment you will continue the design and implementation of.
Comp2513 Forms and CGI Server Applications Daniel L. Silver, Ph.D.
Introduction to Perl & BioPerl Dr G. P. S. Raghava Bioinformatics Centre Bioinformatics Centre IMTECH, Chandigarh Web:
CGI and Perl - Basics Please use speaker notes for additional information!
2 1 Sending Data Using a Hyperlink CGI/Perl Programming By Diane Zak.
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
USING PERL FOR CGI PROGRAMMING
CSU - DCE Advanced Perl CGI Operation - Fort Collins, CO Copyright © XTR Systems, LLC Introduction to the Common Gateway Interface (CGI) on the.
Building PERL Scripts on a Windows system* *and running those scripts on an Apache server!
Data files using cgi/perl Please use speaker notes for additional information!
1 Introduction to Flowcharting. 2 Writing a program Defining the problem –Write down what the program will do Planning –Write down the steps, draw a flowchart.
1 Introduction to Flowcharting. 2 Writing a program Defining the problem –Write down what the program will do Planning –Write down the steps, draw a flowchart.
12 1 Redirection CGI/Perl Programming By Diane Zak.
Mail with Perl/CGI Please use speaker notes for additional information!
COMPUTER PROGRAMMING. Functions What is a function? A function is a group of statements that is executed when it is called from some point of the program.
1 Basic Perl CGI Programming. 2 Issues How and when your program is invoked. Generating Response –HTTP Headers –HTML (or whatever document type you want)
Chapter 9: Perl and CGI Programming CGI Programming Acknowledgement: Some materials are taken from Teach Yourself CGI Programming with PERL 5 in a Week.
11 1 Cookies CGI/Perl Programming By Diane Zak Objectives In this chapter, you will: Learn the difference between temporary and persistent cookies.
3 1 Sending Data Using an Online Form CGI/Perl Programming By Diane Zak.
7 1 User-Defined Functions CGI/Perl Programming By Diane Zak.
CSU - DEO Introduction to CGI - Fort Collins, CO Copyright © XTR Systems, LLC Introduction to the Common Gateway Interface (CGI) Instructor: Joseph DiVerdi,
Functions Please use speaker notes for additional information!
Introduction to CGI/Perl Please use speaker notes for additional information!
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
5 1 Data Files CGI/Perl Programming By Diane Zak.
Intermediate CGI & CGI.pm Webmaster II - Fort Collins, CO Copyright © XTR Systems, LLC CGI Programming & The CGI.pm Perl Module Instructor: Joseph DiVerdi,
ASP. What is ASP? ASP stands for Active Server Pages ASP is a Microsoft Technology ASP is a program that runs inside IIS IIS stands for Internet Information.
CS 330 Class 9 Programming plan for today: More of how data gets into a script Via environment variables Via the url From a form By editing the url directly.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
(C)opyright 2000 Scott/Jones Publishers Introduction to Flowcharting.
IF statements - selection Please use speaker notes for additional information!
 Previous lessons have focused on client-side scripts  Programs embedded in the page’s HTML code  Can also execute scripts on the server  Server-side.
1 HTML forms (cont.)
 2001 Prentice Hall, Inc. All rights reserved. Chapter 7 - Introduction to Common Gateway Interface (CGI) Outline 7.1Introduction 7.2A Simple HTTP Transaction.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Programming with Microsoft Visual Basic th Edition
CS 330 Class 8 Homework A pattern that contains a word with an optional period A pattern that contains Fred with a space (not Freddy) See regexp.txt guest4.htm.
INTERNET APPLICATIONS CPIT405 Forms, Internal links, meta tags, search engine friendly websites.
Sending data with CGI/Perl Please use speaker notes for additional information!
1 CGI (Common Gateway Interface) CmpE 587 Emir Bayraktar Onur Bük.
Lesson 11. CGI CGI is the interface between a Web page or browser and a Web server that is running a certain program/script. The CGI (Common Gateway Interface)
University of Kansas Department of Electrical Engineering and Computer Science Dr. Susan Gauch April 21, 2005 I T T C Introduction to Web Technologies.
Internet/Web Databases
Chapter 7 - Introduction to Common Gateway Interface (CGI)
CS120 The Information Era TOPICS: CGI-Scripts 4/18/05
CGI I: Basics Web Programming.
Section 17.1 Section 17.2 Add an audio file using HTML
Please use speaker notes for additional information!
Lecture 5: Functions and Parameters
CGI I: Basics Web Programming.
Presentation transcript:

Sending data, forms and variables Please use speaker notes for additional information!

#!/usr/bin/perl #grosspwb.cgi - computes gross pay and a dynamic web page print "Content-type: text/html\n\n"; #avoid undeclared variables use strict; #declare variables my($name, $payhr, $hours, $bonus, $gross, $grossyr); $name = "Susan Ash"; $payhr = 55.75; $hours = 40; $bonus = 5000; #calculate gross pay $gross = $payhr * $hours; $grossyr = $payhr * $hours * 52 + $bonus; #create gross pay web page print " \n"; print " Gross Pay \n"; print " Calculate Gross Pay \n"; print " \n"; print "Employee: $name \n"; print "Pay rate: $payhr \n"; print "Hours: $hours \n"; print "Gross pay: $gross \n"; print "Yearly gross pay: $grossyr \n"; print " \n"; By coding use strict, I limit Perl from declaring its on variables. I then define the variables: both the ones that I give a constant value to and the ones that will receive the answers I calculate. I do the calculations using assignment statements.. I print the results on the screen. Note I am printing both a constant and the contents of the variables.

#!/usr/bin/perl #grosspwb.cgi - computes gross pay and a dynamic web page print "Content-type: text/html\n\n"; #avoid undeclared variables use strict; #declare variables my($name, $payhr, $hours, $bonus, $gross, $grossyr); $name = "Susan Ash"; $payhr = 55.75; $hours = 40; $bonus = 5000; #calculate gross pay $gross = $payhr * $hours; $grossyr = $payhr * $hours * 52; $grossyr = $grossyr + $bonus; #create gross pay web page print " \n"; print " Gross Pay \n"; print " Calculate Gross Pay \n"; print " \n"; print "Employee: $name\n"; print "Pay rate: $payhr\n"; print "Hours: $hours\n"; print "Gross pay: $gross \n"; print "Yearly gross pay: $grossyr \n"; print " \n";

Spruce Department Store Get Pay Information Employee Name: Pay per Hour: Hours Worked: Bonus: The ACTION property points to the CGI that will receive the form data and process it. The METHOD can be either POST or GET. From CGI/Perl by Diana Zak (page 58): “The GET method which is the default value for the METHOD property, appends the form data to the end of the URL specified in the ACTION property and is similar to sending the data using a hyperlink. The server retries the data from the URL and stores it in a test string for processing by the CGI script. The POST method, on the other hand, sends the form data in a separate data stream, allowing the Web server to receive the data through what is called ‘standard input’. Because it is more flexible, the POST method is considered the preferred way of sending data to the server”.

#!/usr/bin/perl #grosspay.cgi - computes gross pay and a dynamic web page print "Content-type: text/html\n\n"; use CGI qw(:standard); #avoid undeclared variables use strict; #declare variables my($name, $payhr, $hours, $bonus, $gross, $grossyr); $name = param('Employee'); $payhr = param('PayHour'); $hours = param('NumHours'); $bonus = param('Bonus'); #calculate gross pay $gross = $payhr * $hours; $grossyr = $payhr * $hours * 52 + $bonus; #create gross pay web page print " \n"; print " Gross Pay \n"; print " Calculate Gross Pay \n"; print " \n"; print "Employee: $name \n"; print "Pay rate: $payhr \n"; print "Hours: $hours \n"; print "Gross pay: $gross \n"; print "Yearly gross pay: $grossyr \n"; print " \n"; Note that the names in the parenthesis after param are the same names that were in used in input name on the html form on the previous slide. These names are passed when the information from the form is passed.

From grosspost.html Employee Name: Pay per Hour: Hours Worked: Bonus: From grosspar.cgi #declare variables my($name, $payhr, $hours, $bonus, $gross, $grossyr); $name = param('Employee'); $payhr = param('PayHour'); $hours = param('NumHours'); $bonus = param('Bonus');

Spruce Department Store Get Pay Information Employee Name: Pay per Hour: Hours Worked: Bonus: Uses the get method.

my($name, $payhr, $hours, $bonus, $gross, $grossyr); $name = param('Employee'); $payhr = param('payHour'); $hours = param('NumHours'); $bonus = param('Bonuss'); I changed the names of two of the pieces of information being passed. First, payHour should be PayHour and Bonuss should be Bonus. See previous examples to compare. Notice PayHour and Bonus are being passed but they cannot be received into payHour and Bonuss.

$name = param('Employee'); $payhr = param('PayHour'); $hours = param('NumHours'); $bonus = param('Bonuss'); 25 x 40 = 1000 so gross pay is okay 1000 x 52 = If the bonus was added it would be so clearly the bonus is still a problem.

print " \n"; print " Gross Pay \n" print " Calculate Gross Pay \n"; print " \n"; print "Employee: $name \n" print "Pay rate: $payhr \n"; print "Hours: $hours \n"; print "Gross pay: $gross \n"; print "Yearly gross pay: $grossyr \n"; print " \n"; I removed the ; from the two places shown.

#!/usr/bin/perl #grosspay.cgi - computes gross pay and a dynamic web page print "Content-type: text/html\n\n"; use CGI qw(:standard); use CGI::Carp qw(fatalsToBrowser); #avoid undeclared variables use strict; #declare variables my($name, $payhr, $hours, $bonus, $gross, $grossyr); $name = param('Employee'); $payhr = param('PayHour'); $hours = param('NumHours'); $bonus = param('Bonus'); #calculate gross pay $gross = $payhr * $hours; $grossyr = $payhr * $hours * 52 + $bonus; #create gross pay web page print " \n"; print " Gross Pay \n" print " Calculate Gross Pay \n"; print " \n"; print "Employee: $name \n" print "Pay rate: $payhr \n"; print "Hours: $hours \n"; print "Gross pay: $gross \n"; print "Yearly gross pay: $grossyr \n"; print " \n";

print "Employee: $name \n"; print "Pay rate: \$$payhr \n"; print "Hours: $hours \n"; print "Gross pay: \$$gross \n"; print "Yearly gross pay: \$$grossyr \n";

#!/usr/bin/perl #grosspay.cgi - computes gross pay and a dynamic web page print "Content-type: text/html\n\n"; use CGI qw(:standard); #avoid undeclared variables use strict; #declare variables my($name, $payhr, $hours, $bonus, $gross, $grossyr); $name = param('Employee'); $payhr = param('PayHour'); $hours = param('NumHours'); $bonus = param('Bonus'); #calculate gross pay $gross = $payhr * $hours; $grossyr = $payhr * $hours * 52 + $bonus; #create gross pay web page print " \n"; print " Gross Pay \n"; print " Calculate Gross Pay \n"; print " \n"; print "Employee: $name \n"; printf "Pay rate: \$%.2f \n",$payhr; print "Hours: $hours \n"; printf "Gross pay: \$%.2f \n",$gross; printf "Yearly gross pay: \$%.2f \n",$grossyr; print " \n";