 HTTP Communication  HTTP Communication for Web  Static  Dynamic  Dynamic Content  PHP  PHP Block  PHP Programming Style  Database  MySQL.

Slides:



Advertisements
Similar presentations
PHP I.
Advertisements

JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
1 What is JavaScript? JavaScript was designed to add interactivity to HTML pages JavaScript is a scripting language A scripting language is a lightweight.
Introducing JavaScript
 PHP's name is an recursive acronym for:  Hypertext Preprocessor  PHP script is an HTML- embedded scriting language  Designed to do something only.
Introduction to PHP MIS 3501, Fall 2014 Jeremy Shafer
The Web Warrior Guide to Web Design Technologies
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
JavaScript, Third Edition
PHP Server-side Programming. PHP  PHP stands for PHP: Hypertext Preprocessor  PHP is interpreted  PHP code is embedded into HTML code  interpreter.
 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.
1 CS428 Web Engineering Lecture 19 Data Types (PHP - II)
PHP: Introduction By Trevor Adams.
August Chapter 1 - Essential PHP spring into PHP 5 by Steven Holzner Slides were developed by Jack Davis College of Information Science and Technology.
CSC 318 WEB APPLICATION DEVELOPMENT.  Introduction to Server Scripting language  Client VS Server  Introduction to PHP  PHP Files and Syntax  Function.
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.
2010/11 : [1]Building Web Applications using MySQL and PHP (W1)PHP Recap.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Cookies & Sessions.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
PHP. Why should we learn web programming? No need write socket programming. - You can forget TCP/IP & OSI layers. - Web server handles socket tasks for.
INTERNET APPLICATION DEVELOPMENT For More visit:
Week 9 PHP Cookies and Session Introduction to JavaScript.
Chap 3 – PHP Quick Start COMP RL Professor Mattos.
Client Scripting1 Internet Systems Design. Client Scripting2 n “A scripting language is a programming language that is used to manipulate, customize,
2440: 211 Interactive Web Programming Expressions & Operators.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
CMPS 211 JavaScript Topic 1 JavaScript Syntax. 2Outline Goals and Objectives Goals and Objectives Chapter Headlines Chapter Headlines Introduction Introduction.
Introduction to PHP A user navigates in her browser to a page that ends with a.php extension The request is sent to a web server, which directs the request.
Open Source Software Unit – 3 Presented By Mr. R.Aravindhan.
Variables and ConstantstMyn1 Variables and Constants PHP stands for: ”PHP: Hypertext Preprocessor”, and it is a server-side programming language. Special.
CSC 2720 Building Web Applications Server-side Scripting with PHP.
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.
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
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 supports.
Overview of Form and Javascript fundamentals. Brief matching exercise 1. This is the software that allows a user to access and view HTML documents 2.
JavaScript Scripting language What is Scripting ? A scripting language, script language, or extension language is a programming language.
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming basics.
הרצאה 4. עיבוד של דף אינטרנט דינמי מתוך Murach’s PHP and MySQL by Joel Murach and Ray Harris.  דף אינטרנט דינמי משתנה עפ " י הרצת קוד על השרת, יכול להשתנות.
IT ELECTIVE 2.  Web server Can refer to either the hardware (the computer) or the software (the computer application) that helps to deliver content that.
CHAPTER 6 Introduction to PHP5 Part I อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา 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.
1) PHP – Personal Home Page Scripting Language 2) JavaScript.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP Basics.
Basic Scripting & Variables Yasar Hussain Malik - NISTE.
1 PHP Intro PHP Introduction After this lecture, you should be able to: Know the fundamental concepts of Web Scripting Languages in general, PHP in particular.
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,
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.
PHP using MySQL Database for Web Development (part II)
CGS 3066: Web Programming and Design Spring 2017
Session 2 Basics of PHP.
>> Introduction to JavaScript
Introduction to Dynamic Web Programming
PHP Introduction.
Intro to PHP & Variables
ITS332.
WEB PROGRAMMING JavaScript.
PHP.
Web DB Programming: PHP
HYPERTEXT PREPROCESSOR BY : UMA KAKKAR
IntroductionToPHP Static vs. Dynamic websites
Intro to PHP.
JavaScript CS 4640 Programming Languages for Web Applications
Tutorial 10: Programming with javascript
PHP an introduction.
JavaScript CS 4640 Programming Languages for Web Applications
Presentation transcript:

 HTTP Communication  HTTP Communication for Web  Static  Dynamic  Dynamic Content  PHP  PHP Block  PHP Programming Style  Database  MySQL

Static Web The contents of the web are fixed, hard coded in the markup language (HTML) (What you see is what you get). used to display fixed information which most often does not need to be updated on a regular basis Dynamic Web The contents of the web are coded using client or server side scripting which requires special interpretation to produce interactive or dynamic elements in the page search results number of visitors user login message boards

HTML + JavaScript

HTML + PHP

Benefit of Dynamic Web Content Have ability to customize pages for any given user. Greater ease of modification and update. Extended functionality (login, transactions, communication etc.) Automating the site and allowing it to support itself. Less pages to manually create.

 PHP's name is an recursive acronym for:  Hypertext Preprocessor  PHP script is an HTML- embedded scriting language  Designed to do something only after event occurs.  e.g. when user submit forms  A Server-Side language  the code resides on a host computer that serves Web pages to the requesting visitors (client).  PHP is easy to use for Web development because it has many built-in functions that make web programming simpler, so that programmers can focus on the logic of programming without wasting precious development time

client server URL request HTML PHP Script request HTML

PHP code skeleton: … First style Second style Third style

 Use PHP built in functions  Example  echo ‘Hello Student’;  print “ How are you”;  Case-insensitive for function names  ECHO, echo, Echo  Other print functions  print_r, var_dump - value of variable  print_f - formatting what you print

 White spaces - blank lines, tabs and extra spaces To alter spacing of finished web page, use  - line break  - paragraph To alter spacing of HTML source from PHP, use  echo() or print() over the course of several lines  \n (newline character) within double quotation marks

 Important aspect to dynamic web site development  Viewable in the source but not in the browser window  PHP supports 3 type of comments # this is a comment // this is also a comment /* this is a larger comment that spans two line */

 Rules of thumb Variable name must start with dollar sign ($) Combination of strings, numbers and the underscore First character after dollar sign cannot be a number Case sensitive Assigned value using equals sign (=)

 A quoted chunk of letters, numbers, spaces, punctuation..  Example strings  ‘hello’  ‘software’  ‘1000’  ’12 January, 2006’  String variable – assign a string value to valid variable name  $today =’16 July, 2007’;  To print out  echo $today;  echo “Today is $today”;  Concatenation string  Addition of strings using period (. ).  $day=‘12’;  $month=‘January’;  $year =‘2006’;  $today = $day. ’ ‘. $month. ’ ‘. $year;  Use it extensively when building database queries in later chapters

 Valid number-type variables can be  8  3.14    Arithmetic operators  + addition  - subtraction  * multiplication  / division  % modular  ++ increment  -- decrement

 Functions  round()  $j = 3.14;  $k = round( $j);  number_format()  $p =20980;  $g=number_format($p);  $g=number_format($p,2);

 Specific data type  Retain initial value throughout script  Cannot change once it has been set  Use define()  define (‘AGE’, ‘value’);  Print constant  echo ‘Hello, ‘. AGE; OR  echo ‘Hello,’, AGE;

 Single quote-> values treated literally  Double quote-> interpolated  Example:  $var =‘Hello’;  echo “var equal to $var”;  var equal to hello  echo ‘var equal to $var’;  var equal to $var  echo “\$var is equal to $var”;  $var is equal to hello

 “”  replace variables name with its value and a special character’s code (\$) with its represented value  ‘’  display exactly what you type, except for the escaped single quote (\’) and the escape backslash (\\).

PROGRAMMING WITH PHP

 Creating an HTML form  Handling an HTML form  Conditional and Operators  Validating Form Data  Sending Values to A Script Manually  What are Arrays  For and While Loops

 Managing HTML form with PHP involves 2 steps : 1. Step 1: Create HTML form with any text editor HTML form (.htm/.html) is created using the HTML form tags and various input types. 2. Step 2: Create PHP scripts that receives form data PHP script (.php) is created to receives the submitted form data and handle it.

Step 1: create html form Step 2: create php scripts that receive form data

how dat ais sent (get or post) which page the form data will be send

 If you have a text box in html form with name attribute age, PHP will store the text entered there in a variable called $age (registered global variable)  $age is similar to $_POST[‘age’] (superglobal variables)  eg : ( in HTML form)  eg : ( in PHP scripts) echo “ Thank you, {$_POST[‘age’]} for the following comments”; Age: attributes

 Dynamic web frequently use conditionals to alter script behavior  3 primary terms – if, else, elseif Syntax: if (condition) { // do something! } if (condition) { // do something! } else { // do something else! } if (condition1) { // do something! } elseif (condition2) { // do something else! } else { // do something else! }

 Condition can be TRUE for any number of reasons. Below are common TRUE conditions:  $var, if $var has a value other than 0, an empty string or NULL  isset($var), if $var has any value other than NULL, including 0 and an empty string.  TRUE

 Comparative and Logical Operators SymbolMeaningTypeexample =Is assigned the value ofAssignment$n=1 ==Is equal toComparison$x==$y !=Is not equal toComparison$x!=$y <Less thanComparison$x < $y >Greater thanComparison$x > $y

 switch  Used in place of a long if–elseif–else conditional Syntax : switch ($variable) { case ‘value1’ : // do this break; case ‘value2’ : // do this break; default : // do this break; }

 Use of conditionals and any number of functions, operators and expressions.  Common functions : empty(), strlen(), isset()

 Why validate form? To ensure that something was entered or selected in form elements. To ensure that something was entered or selected in form elements. To ensure that submitted data is of the right type (numeric, string, etc), of the right format (eg: addr), or a specific acceptable value (eg: $gender is either M or F) To ensure that submitted data is of the right type (numeric, string, etc), of the right format (eg: addr), or a specific acceptable value (eg: $gender is either M or F)

 2 ways to pass a PHP script variables and values  Use HTML hidden input type -As long as this code is anywhere between the form tags, the variable $name will have a value of ‘Brian’ in the handling PHP script  To append a value to the handling PHP scripts URL - Emulate the get method of an HTML form

The page (handle_calculator.php) that handles the form (calculator.html) will receive a $source variable to indicate where the data (hidden input) came from. The $source variable need also be validated; is set or not and if it is set with value, is the value correct or not. Observe the action attribute in the form tag below : appended!

 An array can hold multiple, separate pieces of information  List of values  Each value being a string or a number or even another array  Structured as a series of key-value pairs.  Each item in the list, there is a key associate with it.  Support 2 kind of arrays  Indexed – use numbers as the key  Associative – use strings as key

 Example – indexed  $artists  Example – associative  $statesKeyValue0Low 1Aimee 2 Ani Difranco 3Spiritualized KeyValueMDMaryland PAPenssylvania ILIllinois MOMissouri

 To retrieve a specific value from an array, refer to the array name, followed by the key, in square brackets  echo $artists[2];  echo $states[‘MD’];  To print, wrap array name with curly braces  echo “IL is the abbreviation for {$states[‘IL’]}.”;

 Very useful and powerful tool  By default, PHP uses several types of arrays  $_GET to store all of the variables and values sent via the get method  $_POST to store all of the variables and values sent via the post method  $_SESSION, $_COOKIE

 Syntax to create arrays  Add an element at a time  $array[] =‘value’;  $array[] =‘value one’;  $array[‘key’] =‘more values’;  Use array() function to build an entire array  $array =array(‘key’ =>’value’, ‘key2’ => ‘value2’);  $array =array(‘value’,’value2’,’value3’);  Create an array of sequential numbers, use range()  $ten = range(1,10);

 Access every array element, use foreach loop: Syntax : foreach ($array as $value) echo $value ;  Iterate through every element in $array, assigning each element value to the $value variable.  To access both the keys and values Syntax : foreach ($array as $key => $value) echo “The array value at $key is $value”;

 An array consisting of other arrays  Combine 2 arrays into 1 multidimensional array  $states = array (‘MD’ =>’MaryLand’, ‘IL’ =>’Illinois’);  $provinces = array (‘QC’ =>’Quebec’, ‘AB’ =>’Alberta’);  $abbr = array (‘US’ =>$states, ‘Canade =>$provinces’);  To access $states array  $abbr[‘US’];  To access Maryland  $abbr[‘US’][‘MD’]  To print out  echo “The US state whose abbreviation is MD is {$abbr[‘US’][‘MD’]}.”;

 2 functions for converting between strings and arrays  $array = explode (separator, $string);  Turning a string into an array  $string =‘Jan-Feb-Mac-Apr-May’;  $array =explode (‘-’, $string);  $string = implode (glue, $array);  Turning an array to string  $string =implode (‘, ’, $array);  $string= ‘Jan,Feb,Mac,Apr,May’;

 Use built in PHP function  sort() – sort an array by value discarding the original keys  The array keys will be reset after the sorting process  Avoid use this function if key-value relationship is important.  asort() – sort an array by value while maintaining the key  ksort() – sort an array by key  Each of these can sort reverse order by changing them to  rsort(), arsort(), krsort()  shuffle() – to randomize the order of an array

 While loop  If the condition is still true, the loop will be executed Syntax : while (condition) { // do something }  For loop  first the initial expression is run, checked the condition and if true, content of the loop is executed. After execution, checked closing expression with condition again. Syntax : for (initial expression; condition; closing expression) { // do something }