PHP WORKSHOP (Session 1) INFO 257 Supplement. Outline What is PHP ? PHP Language Basics PHP Exercise.

Slides:



Advertisements
Similar presentations
PHP I.
Advertisements

Powerpoint Templates Page 1 Powerpoint Templates Server Side Scripting PHP.
UFCE8V-20-3 Information Systems Development 3 (SHAPE HK) Lecture 3 PHP (2) : Functions, User Defined Functions & Environment Variables.
CHAPTER 3 MORE ON FORM HANDLING INCLUDING MULTIPLE FILES WRITING FUNCTIONS.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Web Database Programming Using PHP.
PHP (2) – Functions, Arrays, Databases, and sessions.
PHP Intro/Overview Squirrel Book pages Server-side Scripting Everything you need to know in one slide 1.Web server (with PHP “plug-in”) gets a.
Website Development Introducing PHP The PHP scripting language Syntax derives from C, Java and Perl Open Source Links to MySql database.
PHP Server-side Programming. PHP  PHP stands for PHP: Hypertext Preprocessor  PHP is interpreted  PHP code is embedded into HTML code  interpreter.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
August Chapter 1 - Essential PHP spring into PHP 5 by Steven Holzner Slides were developed by Jack Davis College of Information Science and Technology.
Advance Database Management Systems Lab no. 5 PHP Web Pages.
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.
PHP : Hypertext Preprocessor
Lecture 6 – Form processing (Part 1) SFDV3011 – Advanced Web Development 1.
Chapter 4 – The Building Blocks Data Types Literals Variables Constants.
2010/11 : [1]Building Web Applications using MySQL and PHP (W1)PHP Recap.
AIT 616 Fall 2002 PHP. AIT 616 Fall 2002 PHP  Special scripting language used to dynamically generate web documents  Open source – Free!!!  Performs.
INTERNET APPLICATION DEVELOPMENT For More visit:
NMED 3850 A Advanced Online Design January 26, 2010 V. Mahadevan.
Chap 3 – PHP Quick Start COMP RL Professor Mattos.
IST 210: PHP BASICS IST 210: Organization of Data IST210 1.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
CS146 Database Systems &Team Projects Spring 2009.
Creating Dynamic Web Pages Using PHP and MySQL CS 320.
1 Session 3: Flow Control & Functions iNET Academy Open Source Web Programming.
20-753: Fundamentals of Web Programming 1 Lecture 12: Javascript I Fundamentals of Web Programming Lecture 12: Introduction to Javascript.
NMD202 Web Scripting Week3. What we will cover today Includes Exercises PHP Forms Exercises Server side validation Exercises.
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.
1 CS428 Web Engineering Lecture 20 Control Structures, Loops and Pointers File Uploading Function (PHP - III)
Class 2Intro to Databases Goals of this class Include & Require in PHP Generating Random Numbers in PHP Arrays – Numerically Indexed and Associative Program.
Variables and ConstantstMyn1 Variables and Constants PHP stands for: ”PHP: Hypertext Preprocessor”, and it is a server-side programming language. Special.
HTML, PHP, and MySQL: Putting It All Together. Making a Form Input tags Types: “text” “radio” “checkboxes” “submit”
CSC 2720 Building Web Applications Server-side Scripting with PHP.
Just a Little PHP Programming PHP on the Server. Common Programming Language Features Comments Data Types Variable Declarations Expressions Flow of Control.
Intro to PHP IST2101. Review: HTML & Tags 2IST210.
Server-Side Scripting with PHP ISYS 475. PHP Manual Website
Introduction to PHP.
>> PHP: Insert Query & Form Processing. Insert Query Step 1: Define Form Variables Step 2: Make DB Connection Step 3: Error Handling Step 4: Define the.
הרצאה 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.
PHP A very brief introduction PHP1. PHP = PHP: Hypertext Processor A recursive acronym! PHP scripts are executed on the server side Executed by (a plugin.
Creating Databases for Web applications Server side vs client side PHP basics Homework: Get your own versions of sending working: both html and Flash!
Creating Databases for Web Applications 3-Tier. Design vs Function vs Content. More SQL. More php. Homework: work on final projects.
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.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP Basics.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Web Database Programming Using PHP.
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.
NMD202 Web Scripting Week2. Web site
Introduction to JavaScript MIS 3502, Spring 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 2/2/2016.
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,
Session 11: Cookies, Sessions ans Security iNET Academy Open Source Web Development.
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.
IST 210: PHP Basics IST 210: Organization of Data IST2101.
Radoslav Georgiev Telerik Corporation
PHP using MySQL Database for Web Development (part II)
Web Database Programming Using PHP
PHP (Session 1) INFO 257 Supplement.
Introduction to Dynamic Web Programming
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Web Database Programming Using PHP
DBW - PHP DBW2017.
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 ©
Web DB Programming: PHP
HYPERTEXT PREPROCESSOR BY : UMA KAKKAR
PHP an introduction.
SEEM 4540 Tutorial 4 Basic PHP based on w3Schools
Presentation transcript:

PHP WORKSHOP (Session 1) INFO 257 Supplement

Outline What is PHP ? PHP Language Basics PHP Exercise

What is PHP ? PHP is a programming language that can do all sorts of things: Evaluate form data sent from a browser Build custom web content to serve the browser Talk to a database Send and receive cookies

Big Picture HTTP Request HTTP Response Process Request Render HTML/CSS/JS Response in Browser Build DOM Web Server Database Apply CSSExecute JS

The Request “Traditional Directory Mapping” Root academics calendar.php Note, we will not be covering MVC

HTML vs. PHP Requests Server will simply return the HTML file Server will 1.Parse the php file, 2.Execute any php code within the file, 3.Then return a dynamically generated html file.

PHP Block <?php //PHP Code… ?> Can put this anywhere and any number of times within the html of your PHP file. The code in PHP Blocks merge together to form a single PHP execution script. So if you define a variable in an earlier block, it will be available in a latter block as well.

Variables $variable_name = value; Data Types String$a = “some string of characters”; Integer (whole #’s)$a = 1; Float (fractional #’s)$a = 1.1; Boolean$a = true; Arrays$a = array(1, 2, 3); ObjectsWe may not have time to get to this, but lets see… ResourcesWe won’t have time to get to this null$a = null; Special type that basically means “nothing”. Very common when working with databases

Functions Define the Function function my_function($param1, $param2){ //code to execute… //possibly “return” a value/object } Call the Function $a = 1; $b = 2; my_function($a, $b); (6 exercises)

echo When you want to spit out some content into your html, use echo <?php echo “Some Text”; echo $variable_name; echo $someArray[1]. “ “. $someArray[2]; ?> Note, there is also a “print” function that is very similar to echo but echo is more useful since it can print out multiple variables/objects with a single call

If… elseif… else if (conditional expression 1){ //code to execute if conditional expression 1 = true } elseif (conditional expression 2){ //code to execute if conditional expression 2 = true } else{ //code to execute none of the conditional expressions are met } The conditional expression needs to be of a boolean (true/false) type. If you provide a variable or function that is not of a boolean type, it will either try to convert it or it will give you an error. Common type conversions: 0 = false, “” = false, “0” = false, [] = false, null = false (6 exercises)

Conditionals ExampleNameResult $a == $b EqualTRUE if $a is equal to $b after type juggling. $a === $b IdenticalTRUE if $a is equal to $b, and they are of the same type. $a != $b Not equalTRUE if $a is not equal to $b after type juggling. $a <> $b Not equalTRUE if $a is not equal to $b after type juggling. $a !== $b Not identicalTRUE if $a is not equal to $b, or they are not of the same type. $a < $b Less thanTRUE if $a is strictly less than $b. $a > $b Greater thanTRUE if $a is strictly greater than $b. $a <= $b Less than or equal toTRUE if $a is less than or equal to $b. $a >= $b Greater than or equal toTRUE if $a is greater than or equal to $b. If compare numbers to strings (i.e. 1 == “1”), then string is converted to number and then compared. Note, this does not happen when you do the “===“ or “!==“ comparison

Logical Operators AND&& OR|| Examples ($a = 1, $b = 2, $c = 2) ($a > $b && $b == $c)  FALSE ($a < $b || $a == $c )  TRUE ($a == $c || $b == $c || somefunc($a))  TRUE

While Loops while (conditional expression){ //code to execute while conditional expression evaluates to true //commonly used to read row results from SQL query } do{ //code executes at least once, then continues to execute while conditional expression evaluates to true } while(conditional expression)

For Loops for($i = 0; $i < 10; $i++){ //execute code //You can use $i in your code } … continue;Stop execution and jump to “4” break;Break out of loop Note, you can use “continue;” and “break” in other loops as well (like the “while” loop)

Working with Strings Escape Characters New line$a = “this is a new line \n”; Backspace$a = “C:\\Some\\Path\\To\\index.php”; Double Quotes$a = “ Google ”; OR…$a = ‘ Google ’; Concatenation echo “add”. “strings”. $a; $query = “SELECT *”; $query.= “FROM table1, table2”; $query.= “WHERE table1.id = table2.id;”; Useful functions ($string = “some random string”) ucwords($string)  “Some Random String” strtoupper($string)  “SOME RANDOM STRING” str_word_count($string)  3 strlen($string)  18 strpos($string, “random”)  5 (returns false if not found)

Working with Arrays Arrays can contain mixed data types $myarray = array(1, “string”, true); Associative Arrays (kind of like Dictionaries, except that the array maintains order) $myarray = array(“somekey” => 1, “anotherkey” => “value”) $myarray[“somekey”]  1 Note, can also access by index: $myarray[0]  1 Can add new arrays elements after array has been instantiated by $myarray[“someotherkey”] = “string”; Multidimensional Arrays $locations = array(); $locations[“sanfran”] = array(“lat” => 100, “long” => 100); $locations[“la”] = array(“lat” => 150, “long” => 150); $locations[“sanfran”][“lat”]  (6 exercises)

Traversing Arrays foreach ($array as $value){ //execute code for each value in the array ($value) } foreach ($array as $key => $value){ //execute code for each key/value in the array ($value, $key) } There are MANY functions that operate on arrays, including sorting, merging, poping, pushing, shifting, splicing, etc. Check out php.net for a full list…

isset() vs. empty() isset() checks to see if a variable is “set,” meaning it is not null. Returns false if not set and true otherwise. empty() checks to see whether a variables value is empty, meaning whether or not it evaluates to false $a = 0; $b = “”; $c = null; $d = “string”; isset($a)  Trueempty($a)  True isset($b)  Trueempty($b)  True isset($c)  Falseempty($c)  True isset($d)  Trueempty($d)  False These are used a lot to check whether form inputs sent empty values or whether database results contain null values…

PHP Exercise 9/26 PHP WORKSHOP (slides, php_exercise.zip)

Next Time PHP Classes Making SQL calls to your MySQL Database  Reading the results  Rendering HTML from the results Sending Data to the Server

Super Globals There are predefined “Super Global” variables that are made available to you through the PHP runtime that you can use within your PHP code. Super GlobalContent $_SERVERContains info about the web server environment such as Server Name, Request Method, Document Root, etc. $_GETContains any GET variables in the URL query string $_POSTContains any POST variables submitted via a form post submission $_COOKIEContains any HTTP Cookie Info $_FILESContains information on POST file uploads $_SESSIONContains information about any variables registered in a session (if created) There are some other super globals but these are the main ones…

Include Note, in your folder structure it is a good idea to create a specific folder that contains all your “include files” Index.php nav.php footer.php nav.php footer.php

Popular Uses of Include Including a set of PHP functions and/or classes Including any variables that are defined in other PHP files (like $document_root, $your_variable, etc.) Including HTML that appears on more than 1 of your pages (i.e. menu, header, footer, sidebars, widgets, etc.) Including objects that get instantiated in other PHP files (i.e. including a connection handle to your MySQL database)