PHP PART 2.

Slides:



Advertisements
Similar presentations
UFCE8V-20-3 Information Systems Development 3 (SHAPE HK) Lecture 3 PHP (2) : Functions, User Defined Functions & Environment Variables.
Advertisements

Lecture 6/2/12. Forms and PHP The PHP $_GET and $_POST variables are used to retrieve information from forms, like user input When dealing with HTML forms.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Web Database Programming Using PHP.
Web Database Programming Input Validation. User Input on the Web Web browser built-in mechanisms –HTML Forms HTTP POST method –Hyperlinks HTTP GET method.
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic PHP.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Tutorial 11 Working with Operators and Expressions
Tutorial 14 Working with Forms and Regular Expressions.
Dr. Qusai Abuein1 Internet & WWW How to program Chap.(26) PHP (Personal Home Page)
Guide To UNIX Using Linux Third Edition
1 CS 482 Web Programming and Scripting Week 6 – Installing Apache, PHP, MySQL and Using the Software.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 25 – Perl and CGI (Common Gateway Interface) Outline 25.1 Introduction 25.2 Perl 25.3 String Processing.
XP Tutorial 14 New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with Forms and Regular Expressions Validating a Web Form with JavaScript.
Last Updated March 2006 Slide 1 Regular Expressions.
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.
Advance web Programming Chapter 3: MySQL Date: 28 April 2014 Advance web Programming Chapter 3: MySQL Date: 28 April 2014 Dr. Mogeeb A. A. Mosleh .
_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition1  Wiley and the.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 26 - PHP Outline 26.1 Introduction 26.2 PHP 26.3 String Processing and Regular Expressions 26.4.
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.
Chapter 4 Handling User Input PHP Programming with MySQL 2nd Edition
Chapter 4 – The Building Blocks Data Types Literals Variables Constants.
Chapter 4: Basics of PHP 42. Topics Introduction Creating and Executing PHP Programs Variables Operators Constant Arrays String Processing and Regular.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 26 - PHP Outline 26.1 Introduction 26.2 PHP 26.3 String Processing and Regular Expressions 26.4.
Chap 3: Web Programming (CCSB144) - PHP 42 Chapter 4 - PHP Outline Introduction PHP String Processing and Regular Expressions Viewing Client/Server Environment.
 2008 Pearson Education, Inc. All rights reserved PHP.
Jozef Goetz contribution, Credits: Parts of the slides are based on slides created by textbook authors, P.J. Deitel and H. M. Deitel by Prentice.
Tutorial 14 Working with Forms and Regular Expressions.
Chapter 6: Forms JavaScript - Introductory. Previewing the Product Registration Form.
 2003 Prentice Hall, Inc. All rights reserved. 1 PHP Outline 26.1 Introduction 26.2 PHP 26.3 String Processing and Regular Expressions 26.4 Viewing Client/Server.
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
JavaScript, Fourth Edition Chapter 5 Validating Form Data with JavaScript.
Website Development with PHP and MySQL Saving Data.
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.
 2008 Pearson Education, Inc. All rights reserved PHP.
Server-Side Scripting with PHP ISYS 475. PHP Manual Website
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
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.
XP Tutorial 7 New Perspectives on JavaScript, Comprehensive 1 Working with Forms and Regular Expressions Validating a Web Form with JavaScript.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Web Database Programming Using PHP.
NMD202 Web Scripting Week2. Web site
CGS 3066: Web Programming and Design Spring 2016 PHP.
Simple PHP Web Applications Server Environment
Web Database Programming Using PHP
Chapter 5 Validating Form Data with JavaScript
CGS 3066: Web Programming and Design Spring 2017
Chapter 19 PHP Part I Credits: Parts of the slides are based on slides created by textbook authors, P.J. Deitel and H. M. Deitel by Prentice Hall ©
In this session, you will learn to:
Receiving form Variables
CS 330 Class 7 Comments on Exam Programming plan for today:
Chapter 26 - PHP Outline 26.1 Introduction 26.2 PHP
CS 371 Web Application Programming
How to Write Web Forms By Mimi Opkins.
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Web Database Programming Using PHP
Arrays An array in PHP is an ordered map
PHP Functions Besides the built-in PHP functions, we can create our own functions. A function is a block of statements that can be used repeatedly in.
19.10 Using Cookies A cookie is a piece of information that’s stored by a server in a text file on a client’s computer to maintain information about.
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 ©
23 PHP.
Chapter 19 PHP Part II Credits: Parts of the slides are based on slides created by textbook authors, P.J. Deitel and H. M. Deitel by Prentice Hall ©
Working with Forms and Regular Expressions
PHP.
Web DB Programming: PHP
Web Programming Language
Lecture 5: Functions and Parameters
PHP Forms and Databases.
Introduction to HTML: Forms
PHP an introduction.
PHP-II.
Presentation transcript:

PHP PART 2

23.2 PHP Basics (Cont.) Array names, like other variables, begin with the $ symbol. Function count returns the total number of elements in the array. Function array creates an array that contains the arguments passed to it.

23.2 PHP Basics (Cont.) Arrays with nonnumeric indices are called associative arrays. You can create an associative array using the operator => Function reset sets the internal pointer to the first array element. Function key returns the index of the element currently referenced by the internal pointer, function next moves the internal pointer to the next element. The foreach statement, designed for iterating through arrays,

Outline (1 of 4) Automatically creates array $first arrays.php (1 of 4) Automatically creates array $first Sets the first element of array $first to the string “zero” “three” is appended to the end of array $first Returns the number of elements in the array

Outline arrays.php (2 of 4) Function array creates array $second with its arguments as elements Creates associative array $third Sets the internal pointer to the first array element in $third Returns the index of the element being pointed to Moves the internal pointer to the next element and returns it

Outline arrays.php (3 of 4) Uses operator => to initialize the element with index “January” to have value “first” Iterates through each element in array $fourth Stores the index of the element Stores the value of the element

Outline arrays.php (4 of 4)

23.3 String Processing and Regular Expressions Function strcmp compares two strings. The function returns -1 if the first string alphabetically precedes the second string, 0 if the strings are equal, and 1 if the first string alphabetically follows the second.

Outline compare.php (1 of 2) Checks whether the ith element of the fruits array preceeds the string banana

Outline compare.php (2 of 2) Uses relational operators to compare the element of the fruits array with the string apple

23.3 String Processing and Regular Expressions (Cont.) Function ereg receives a regular expression pattern to search for and the string to search. Function eregi performs case-insensitive pattern matches. Regular expressions can include metacharacters that specify patterns. caret (^) metacharacter matches the beginning of a string, dollar sign ($) matches the end of a string. period (.) metacharacter matches any single character.

23.4 Form Processing and Business Logic The arrays $_GET and $_POST retrieve information sent to the server by HTTP get and post requests, respectively. Using method = "post" appends form data to the browser request that contains the protocol and the requested resource’s URL. Scripts located on the web server’s machine can access the form data sent as part of the request.

Fig. 23.11 | Some useful superglobal arrays. Global arrays are associative arrays predefined by PHP that hold environment or the web server and are accessible in any scope. DETAILED INFORMATION http://www.php.net/manual/tr/reserved.variables.server.php Fig. 23.11 | Some useful superglobal arrays.

Outline form.html (1 of 4) Appends form data to the browser request that contains the protocol and the URL of the requested resource Form data is posted to form.php to be processed

Outline (2 of 4) Creates form fields form.html (2 of 4) Creates form fields Creates drop-down list with book names

Outline form.html (3 of 4) Creates radio buttons with “Windows XP” initially selected

Outline form.html (4 of 4)

Good Programming Practice 23.1 Use meaningful XHTML object names for input fields. This makes PHP scripts that retrieve form data easier to understand.

23.4 Form Processing and Business Logic (Cont.) Function extract creates a variable/value pair corresponding to each key/value pair in the associative array passed as an argument. Business logic, or business rules, ensures that only valid information is stored in databases. Function die terminates script execution.

Outline form.php (1 of 5)

Creates a variable/value pair for each key/value pair in $_POST Outline form.php (2 of 5) Ensures that phone number is in proper format Terminates execution and closes the document properly

Outline form.php (3 of 5) Prints the value entered in the email field in form.html

Outline form.php (4 of 5)

Outline form.php (5 of 5)