Practical PHP IDIA 618.185 Spring 2012 Bridget M. Blodgett.

Slides:



Advertisements
Similar presentations
Cookies, Sessions. Server Side Includes You can insert the content of one file into another file before the server executes it, with the require() function.
Advertisements

The Web Warrior Guide to Web Design Technologies
JavaScript Forms Form Validation Cookies CGI Programs.
Scripting Languages Chapter 6 I/O Basics. Input from STDIN We’ve been doing so with $line = chomp($line); Same as chomp($line= ); line input op gives.
1 Outline 13.1Introduction 13.2A Simple Program: Printing a Line of Text in a Web Page 13.3Another JavaScript Program: Adding Integers 13.4Memory Concepts.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Display a 12-Month Calendar CS-2301 D-term Programming Assignment #2 12-Month Calendar CS-2301 System Programming C-term 2009 (Slides include materials.
 2002 Prentice Hall. All rights reserved. 1 Intro: Java/Python Differences JavaPython Compiled: javac MyClass.java java MyClass Interpreted: python MyProgram.py.
Chapter 10 Managing State Information PHP Programming with MySQL.
Assignment #2, 12- month Calendar CS-2301, B-Term Programming Assignment #2 12-Month Calendar CS-2301, System Programming for Non-Majors (Slides.
The printf Method The printf method is another way to format output. It is based on the printf function of the C language. System.out.printf(,,,..., );
MS3304: Week 4 PHP & HTML Forms. Overview HTML Forms elements refresher Sending data to a script via an HTML form –The post vs. get methods –Name value.
PHP Tutorials 02 Olarik Surinta Management Information System Faculty of Informatics.
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.
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.
INTERNET APPLICATION DEVELOPMENT For More visit:
Lab Assignment 7 | Web Forms and Manipulating Strings Interactive Features Added In this assignment you will continue the design and implementation of.
11 Chapter 3 DECISION STRUCTURES CONT’D. 22 FORMATTING FLOATING-POINT VALUES WITH THE DecimalFormat CLASS We can use the DecimalFormat class to control.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Cookies & Sessions.
CHAPTER 12 COOKIES AND SESSIONS. INTRO HTTP is a stateless technology Each page rendered by a browser is unrelated to other pages – even if they are from.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
Functions & Objects IDIA 618 Spring 2012 Bridget M. Blodgett.
JavaScript, Fourth Edition
 2004 Prentice Hall, Inc. All rights reserved. 1 Chapter 11 - JavaScript: Arrays Outline 11.1 Introduction 11.2 Arrays 11.3 Declaring and Allocating Arrays.
NMED 3850 A Advanced Online Design January 26, 2010 V. Mahadevan.
Writing Web Pages By Shyam Gurram. Agenda Writing Web Pages Delimiting PHP Program Units. Displaying Output to Web Pages Putting Comments in PHP Programs.
Week 9 PHP Cookies and Session Introduction to JavaScript.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
IST 210: PHP BASICS IST 210: Organization of Data IST210 1.
PHP meets MySQL.
Chapter 8 Cookies And Security JavaScript, Third Edition.
Chapter 3 Processing and Interactive Input. 2 Assignment  The general syntax for an assignment statement is variable = operand; The operand to the right.
Creating Dynamic Web Pages Using PHP and MySQL CS 320.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
Website Development with PHP and MySQL Saving Data.
PHP2. PHP Form Handling The PHP $_GET and $_POST variables are used to retrieve information from forms, like user input. Name: Age:
11 1 Cookies CGI/Perl Programming By Diane Zak Objectives In this chapter, you will: Learn the difference between temporary and persistent cookies.
HTML FORMS GET/POST METHODS. HTML FORMS HTML Forms HTML forms are used to pass data to a server. A form can contain input elements like text fields, checkboxes,
3 1 Sending Data Using an Online Form CGI/Perl Programming By Diane Zak.
PHP. $_GET / $_POST / $_SESSION PHP uses predefined variables to provide access to important information about the server and requests from a browser.
Cookies and Sessions IDIA 618 Fall 2014 Bridget M. Blodgett.
 2000 Deitel & Associates, Inc. All rights reserved. Outline 8.1Introduction 8.2A Simple Program: Printing a Line of Text in a Web Page 8.3Another JavaScript.
הרצאה 4. עיבוד של דף אינטרנט דינמי מתוך Murach’s PHP and MySQL by Joel Murach and Ray Harris.  דף אינטרנט דינמי משתנה עפ " י הרצת קוד על השרת, יכול להשתנות.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
JavaScript 1 COE 201- Computer Proficiency. Introduction JavaScript scripting language ▫Originally created by Netscape ▫Facilitates disciplined approach.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Formatting Output. Formatting features of printf System.out.printf can perform the following Rounding floating-point values Aligning properly a column.
XP 1 ﴀ New Perspectives on Microsoft Office 2003, Premium Edition Excel Tutorial 2 Microsoft Office Excel 2003 Tutorial 2 – Working With Formulas and Functions.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Input and Output.
SESSIONS 27/2/12 Lecture 8. ? Operator Similar to the if statement but returns a value derived from one of two expressions by a colon. Syntax: (expression)
Since you’ll need a place for the user to enter a search query. Every form must have these basic components: – The submission type defined with the method.
8 th Semester, Batch 2008 Department of Computer Science SSUET.
 A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user's computer. Each time the same computer requests.
Basic ActionScript and PHP Cis 126. Getting Started set up a basic folder structure so we can keep our files organized. Mirror this structure on your.
Trinity College Dublin, The University of Dublin GE3M25: Computer Programming for Biologists Python, Class 2 Karsten Hokamp, PhD Genetics TCD, 17/11/2015.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Student Grades Application Introducing Two-Dimensional Arrays and RadioButton.
PHP Form Processing * referenced from
Unit-6 Handling Sessions and Cookies. Concept of Session Session values are store in server side not in user’s machine. A session is available as long.
PHP Tutorial. What is PHP PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
 2001 Prentice Hall, Inc. All rights reserved. Outline 1 JavaScript.
Session 2 Basics of PHP.
CHAPTER 5 SERVER SIDE SCRIPTING
Chapter 19 PHP Part III Credits: Parts of the slides are based on slides created by textbook authors, P.J. Deitel and H. M. Deitel by Prentice Hall ©
In Class Program: Today in History
PHP.
Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions
Advanced Concepts and AJAX
HTML Forms What are clients? What are servers?
PHP-II.
Presentation transcript:

Practical PHP IDIA Spring 2012 Bridget M. Blodgett

$_GET and $_POST $_GET and $_POST are system reserved variable names that take the input from a form submission and save the values to an associative array – The index is set to the id of the input The variable should be used when the relevant form submission type is included in the HTML page

$_REQUEST $_REQUEST works just like $_GET and $_POST but it will work regardless of the form submission type – It also pulls information from $_COOKIE It can be useful if several different forms direct to the same page since only one call is needed to read all the different types of input

$_COOKIE Cookies are a way of identifying users who visit the site and allow for some more dynamic information handling – They can tell when a user has logged in and allow additional access to that person setcookie(name, value, expire, path, domain); – Sets a cookie on the user computer (must appear before the opening $_COOKIE will retrieve the cookie information while isset() sees if a cookie has been assigned yet

printf printf controls the format of output by allowing special formatting characters in a string SpecifierConversion action on argument argExample (for an arg of 123) %Display a % character (no arg is required)% bDisplay arg as a binary integer cDisplay ASCII character for the arg{ dDisplay arg as a signed decimal integer123 eDisplay arg using scientific notation e+2 fDisplay arg as floating point oDisplay arg as an octal integer173 sDisplay arg as a string123 uDisplay arg as an unsigned decimal123 xDisplay arg in lowercase hexadecimal7b XDisplay arg in uppercase hexadecimal7B Table 7-1. The printf conversion specifiers

printf You can have as many specifiers as you like in a printf function, Must pass a matching number of arguments Each specifier is prefaced by a % symbol printf("My name is %s. I'm %d years old, which is %X in hexadecimal", 'Simon', 33, 33);

Precision Setting PHP allows you to specify how many places appear after the decimal point upon the completion of a calculation Place the %.placenumber between the conversion specifier – printf("The result is: $%.2f", / 12); – Example 7-1

String Precision The same concepts work with strings When specifying padding, if a string is already of equal or greater length than that value [padding] it will be ignored – unless a cutoff value is given that shortens the string back to less than the padding value.

sprintf() Allows you to store the value of a string precision specification to another variable for later use or manipulation $out = sprintf("The result is: $%.2f", / 12); echo $out;

Date and time PHP uses standard Unix timestamps – number of seconds since the start of January 1, 1970 – Since it is seconds some manipulation is needed to read the time in a “normal” format This time next week looks like: – echo time() + 7 * 24 * 60 * 60;

Review Questions

Loops Using a for loop, write a script that will send to the browser a list of squares for the numbers Use the format, "1 * 1 = 1", and be sure to include code to print each formula on a different line.

Switch Statement Create a form to accept user’s input of the day of the week Make a switch statement that takes that input and prints the correct statement – Laugh on Monday, laugh for danger. Laugh on Tuesday, kiss a stranger. Laugh on Wednesday, laugh for a letter. Laugh on Thursday, something better. Laugh on Friday, laugh for sorrow. Laugh on Saturday, joy tomorrow. Remember to include a general response for any input that is not in the poem. To make things a little more interesting, include a 'Back' button on the response so that the user can go back and try different days.

Arrays Create an array of modes of transportation, including Automobile, Jet, Ferry, Subway. Print the following statement to the browser: "Travel takes many forms, whether across town, across the country, or around the world. Here is a list of some common modes of transportation:“ Follow this with an unordered list created by iterating through the array variable you created. Give the user a text box and ask the user to add other modes of transportation to the list, separated by commas. When the user clicks 'Go', process the input with array functions to send back the original list with the user's additions. Include another text box with the text "Add more?" and another submit button. When the user clicks this button, the page should reload with the new additions added to the previously expanded list

Functions Create an array called $months. Use the names of the months as keys, and the number of days for each month as values Write a function to create an option element for a form's select field. – Make sure each option will be upper case. – Both the array and the function should precede the HTML for the page. Create a form for the user with the request, "Please choose a month." and a select field with the months as options – loop through the array you created and use the function to create the option elements. When the user clicks the submit button, return the statement "The month of $month has $number days