INTERNET APPLICATION DEVELOPMENT For More visit:

Slides:



Advertisements
Similar presentations
PHP Form and File Handling
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.
XAMPP: Cross – Apache, MySQL, Php, Perl + FileZilla, Tomcat NetBeans: IDE PHP Installation.
Intermediate PHP & MySQL
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.
PHP Forms. I. Using PHP with HTML Forms A very common application of PHP is to have an HTML form gather information from a website's visitor and then.
IS1500: Introduction to Web Development
Outline o What is an array ? o Indexed array o Associative array o Multidimensional array.
04/09/20151 PHP & MySQL 'Slide materials are based on W3Schools PHP tutorial, 'PHP website 'MySQL website.
PHP – Get & Post; Functions; and Arrays IS6116 – 07 th February 2011.
PHP Tutorials 02 Olarik Surinta Management Information System Faculty of Informatics.
Advance Database Management Systems Lab no. 5 PHP Web Pages.
Application Development Description and exemplification of server-side scripting language for server connection, database selection, execution of SQL queries.
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.
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.
(c) Manzur Ashraf, Short course, KFUPM PHP & MySQL 1 Basic PHP Class 2.
PHP Forms and User Input The PHP $_GET and $_POST variables are used to retrieve information from forms, like user input.
Lecture 6 – Form processing (Part 1) SFDV3011 – Advanced Web Development 1.
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
Lecture 7 – Form processing (Part 2) SFDV3011 – Advanced Web Development 1.
Week 7. Lecture 3 PHP Forms. PHP forms In part 2 of this course, we discussed html forms, php form is similar. Lets do a quick recap of the things we.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
PHP Arrays. Outline o What is array in PHP ? o Numeric array o Associative array o Multidimensional array.
Week 7. Lecture 2 Functions, Arrays, PHP&MySQL. Function with More than one argument and a return statement For a function to return a value, the return.
PHP - Introduction Week 5 Dr. Ken Cosh Introducing PHP 1.
Open Source Software Unit – 3 Presented By Mr. R.Aravindhan.
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:
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,
Web Programming Language Week 5 Dr. Ken Cosh Introducing PHP 1.
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.
PHP. What is PHP? PHP stands for PHP: Hypertext Preprocessor PHP is a server-side scripting language, like ASP PHP scripts are executed on the server.
Julian Springer Room 42 Joe Slovo.  W3 schools recommend that you have a basic understanding of HTML and of JavaScript before attempting to grasp PHP.
PHP Constructs Advance Database Management Systems Lab no.3.
PHP. $_GET / $_POST / $_SESSION PHP uses predefined variables to provide access to important information about the server and requests from a browser.
Server-Side Scripting with PHP ISYS 475. PHP Manual Website
Introduction to PHP.
ITM © Port, Kazman1 ITM 352 More on Forms Processing.
Part 2 Lecture 9 PHP Superglobals and Form Handling.
הרצאה 4. עיבוד של דף אינטרנט דינמי מתוך Murach’s PHP and MySQL by Joel Murach and Ray Harris.  דף אינטרנט דינמי משתנה עפ " י הרצת קוד על השרת, יכול להשתנות.
CHAPTER 7 Introduction to PHP5 Part II อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา 1.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
HTML Forms. A form is simply an area that can contain form fields. Form fields are objects that allow the visitor to enter information - for example text.
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.
JavaScript. JavaScript Introduction JavaScript is the world's most popular programming language. It is the language for HTML and the web, for servers,
PHP Syntax You cannot view the PHP source code by selecting "View source" in the browser - you will only see the output from the PHP file, which is plain.
 An array stores multiple values in one single variable.  Example: Output: I like Honda Civic, BMW and Toyota.
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,
11 – Introduction to PHP(1) Informatics Department Parahyangan Catholic University.
PHP Tutorial. What is PHP PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.
CGS 3066: Web Programming and Design Spring 2016 PHP.
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,
Radoslav Georgiev Telerik Corporation
PHP. What is PHP? PHP stands for PHP: Hypertext Preprocessor PHP is a server-side scripting language, like ASP PHP scripts are executed on the server.
PHP – Hypertext Preprocessor.
A pache M ySQL P hp Robert Mudge Reference:
Very often when you write code, you want to perform different actions for different decisions. You can use conditional statements in your code to do this.
CGS 3066: Web Programming and Design Spring 2017
Session 2 Basics of PHP.
CHAPTER 5 SERVER SIDE SCRIPTING
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
8th Semester, Batch 2008 Department of Computer Science SSUET.
PHP FORM HANDLING Post Method
Basic PHP Lecture by Nutthapat Keawrattanapat
HYPERTEXT PREPROCESSOR BY : UMA KAKKAR
PHP an introduction.
PHP PROF. S. LAKSHMANAN, DEPT. OF B. VOC. (SD & SA),
PHP-II.
PHP By Prof. B.A.Khivsara Note: The material to prepare this presentation has been taken from internet and are generated only for students reference and.
Presentation transcript:

INTERNET APPLICATION DEVELOPMENT For More visit:

PHP Arrays What is an Array? A variable is a storage area holding a number or text. The problem is, a variable will hold only one value. An array is a special variable, which can store multiple values in one single variable. If you have a list of items (a list of car names, for example), storing the cars in single variables could look like this: $cars1="Saab"; $cars2="Volvo"; $cars3="BMW";

However, what if you want to loop through the cars and find a specific one? And what if you had not 3 cars, but 300? The best solution here is to use an array! An array can hold all your variable values under a single name. And you can access the values by referring to the array name. Each element in the array has its own index so that it can be easily accessed.

In PHP, there are three kind of arrays: Numeric array - An array with a numeric index Associative array - An array where each ID key is associated with a value Multidimensional array - An array containing one or more arrays Numeric array A numeric array stores each array element with a numeric index. There are two methods to create a numeric array. 1. In the following example the index are automatically assigned (the index starts at 0):

$cars=array("Saab","Volvo","BMW","Toyota"); 2. In the following example we assign the index manually: Example: <?php $cars[0]="Saab"; $cars[1]="Volvo"; $cars[2]="BMW"; $cars[3]="Toyota"; echo $cars[0]. " and ". $cars[1]. " are Swedish cars."; ?> The output is : Saab and Volvo are Swedish cars.

Associative Arrays In an associative array, each ID key is associated with a value. When storing data about specific named values, a numerical array is not always the best way to do it. With associative arrays we can use the values as keys and assign values to them. Example: In this example we use an array to assign ages to the different persons: $ages = array("Ahmad"=>32, "Ali"=>30, "khaled"=>34);

This example is the same as the previous example, but shows a different way of creating the array: $ages['Ahmad'] = "32"; $ages['Ali'] = "30"; $ages['khaled'] = "34"; How to handle the length of an arry. By using count function which Counts all elements in an array count($Array_Name);

example <?php $cars=array("Saab","Volvo","BMW","Toyota"); $lenght=count ($cars); For ($i=0;$i<length; $i++) Echo $cars[$i]. " "; ?> multidimensional array In a multidimensional array, each element in the main array can also be an array. And each element in the sub-array can be an array, and so on. $shop = array( array("rose", 1.25, 15), array("daisy", 0.75, 25), array("orchid", 1.15, 7) );

The foreach Loop The foreach loop is used to loop through arrays. Syntax: foreach ($array as $value) { code to be executed; } For every loop iteration, the value of the current array element is assigned to $value (and the array pointer is moved by one) - so on the next loop iteration, you'll be looking at the next array value.

Example <?php $x=array("one", "two", "three"); foreach ($x as $value) { echo $value. " "; } ?> The output: one two three

PHP Functions The real power of PHP comes from its functions. In PHP, there are more than 700 built-in functions. To keep the script from being executed when the page loads, you can put it into a function. A function will be executed by a call to the function. You may call a function from anywhere within a page. How to Create a PHP Function. Syntax: function functionName() { code to be executed; }

PHP function guidelines: Give the function a name that reflects what the function does The function name can start with a letter or underscore (not a number) Calling PHP Functions PHP functions are called by using the name declared when the function was defined, together with any values that need to be passed through as parameters. The following example both defines and then calls our addNumbers() function:

Example <?php function addNumbers ($arg1, $arg2) { return $arg1 + $arg2; } $var1 = 10; $var2 = 20; echo addNumbers( $var1, $var2); ?>

PHP Form Handling The most important thing to notice when dealing with HTML forms and PHP is that any form element in an HTML page will automatically be available to your PHP scripts. Example The example below contains an HTML form with two input fields and a submit button: MY SIMPLE FORM IN HTML

Name: Age:

When a user fills out the form above and click on the submit button, the form data is sent to a PHP file, called " welcom.php“ which is as the follow: <?php print " wellcome: ". $_POST[fname]. " "; echo " you are : ". $_POST[fage]. "years old."; ?>

Form Validation User input should be validated on the browser whenever possible (by client scripts). Browser validation is faster and reduces the server load. You should consider server validation if the user input will be inserted into a database. A good way to validate a form on the server is to post the form to itself, instead of jumping to a different page. The user will then get the error messages on the same page as the form. This makes it easier to discover the error

The $_GET Variable The predefined $_GET variable is used to collect values in a form with method="get" Information sent from a form with the GET method is visible to everyone (it will be displayed in the browser's address bar) and has limits on the amount of information to send. Example Name: Age:

The $_GET Variable When the user clicks the "Submit" button, the URL sent to the server could look something like this: The "welcome.php" file can now use the $_GET variable to collect form data. the names of the form fields will automatically be the keys in the $_GET array: Welcome. You are years old!

When to use method="get"? When using method="get" in HTML forms, all variable names and values are displayed in the URL. Note: This method should not be used when sending passwords or other sensitive information! However, because the variables are displayed in the URL, it is possible to bookmark the page. This can be useful in some cases. Note: The get method is not suitable for very large variable values. It should not be used with values exceeding 2000 characters.

The $_POST Variable The predefined $_POST variable is used to collect values from a form sent with method="post". Information sent from a form with the POST method is invisible to others and has no limits on the amount of information to send. Note: However, there is an 8 Mb max size for the POST method, by default (can be changed by setting the post_max_size in the php.ini file). Example: Name: Age:

The $_POST Variable When the user clicks the "Submit" button, the URL will look like this: The "welcome.php" file can now use the $_POST variable to collect form data. the names of the form fields will automatically be the keys in the $_POST array: Welcome ! You are years old.

When to use method="post"? Advantage: Information sent from a form with the POST method is invisible to others and has no limits on the amount of information to send. Disadvantage: because the variables are not displayed in the URL, it is not possible to bookmark the page.

The PHP $_REQUEST Variable The predefined $_REQUEST variable contains the contents of both $_GET, $_POST, and $_COOKIE. The $_REQUEST variable can be used to collect form data sent with both the GET and POST methods. Example: Welcome ! You are years old.