1 PHP  Introduction to PHP  Basic Syntax of PHP Variables, Constant, Data Type, Type Casting  Getting Data From Client  PHP Database Manipulation.

Slides:



Advertisements
Similar presentations
Copyright © 2003 Pearson Education, Inc. Slide 1-1 The Web Wizards Guide to PHP by David A. Lash.
Advertisements

PHP I.
This is Java Jeopardy.
Chapter Three Arithmetic Expressions and Assignment Statements
Chapter 2 JAVA FUNDAMENTALS
Introduction to PHP MIS 3501, Fall 2014 Jeremy Shafer
 2005 Pearson Education, Inc. All rights reserved Introduction.
1 PHP Statement Constructs Server Scripting. 5-2 Basic Statement All Statements end in a semicolon. Statements are delimited from the HTML code by enclosing.
PHP Introduction.
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic PHP.
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.
Java An introduction. Example 1 public class Example1 { public static void main (String [] args) { System.out.println (“This is the first example”); int.
Introduction to PHP (Part-1) Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.
ASP.NET Programming with C# and SQL Server First Edition
PHP Server-side Programming. PHP  PHP stands for PHP: Hypertext Preprocessor  PHP is interpreted  PHP code is embedded into HTML code  interpreter.
Basic Elements of C++ Chapter 2.
Introduction to scripting
PHP Workshop ‹#› PHP: The Basics. PHP Workshop ‹#› What is it? PHP is a scripting language commonly used on web servers. –Stands for “PHP: Hypertext Preprocessor”
Lecture 2 Introduction to PHP MIS 3501, Spring 2014 Jeremy Shafer Department of MIS Fox School of Business Temple University January 30, 2014.
August Chapter 1 - Essential PHP spring into PHP 5 by Steven Holzner Slides were developed by Jack Davis College of Information Science and Technology.
Chapter 4: Basics of PHP 42. Topics Introduction Creating and Executing PHP Programs Variables Operators Constant Arrays String Processing and Regular.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
IDK0040 Võrgurakendused I harjutus 06: PHP: Introduction Deniss Kumlander.
Nael Alian Introduction to PHP
Chapter 2 Basic Elements of Java. Chapter Objectives Become familiar with the basic components of a Java program, including methods, special symbols,
November 2003Bent Thomsen - FIT 6-11 IT – som værktøj Bent Thomsen Institut for Datalogi Aalborg Universitet.
Input, Output, and Processing
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Copyright © 2012 Pearson Education, Inc. Chapter 2: Introduction to C++
Variables and ConstantstMyn1 Variables and Constants PHP stands for: ”PHP: Hypertext Preprocessor”, and it is a server-side programming language. Special.
Introduction to PHP Advanced Database System Lab no.1.
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.
Introduction to Computer Programming
Introduction to Programming JScript Six Scripting functions Discuss functions Password Example.
VARIABLES Programmes work by manipulating data placed in memory. The data can be numbers, text, objects, pointers to other memory areas, and more besides.
 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.
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.
Creating PHP Pages Chapter 6 PHP Variables, Constants and Operators.
JavaScript 1 COE 201- Computer Proficiency. Introduction JavaScript scripting language ▫Originally created by Netscape ▫Facilitates disciplined approach.
PHP Workshop ‹#› أطلق إبداعك 2 أطلق إبداعك 2 مدرس معتمد من مركز زووم PHP: The Basics.
PHP Programming with MySQL Slide 3-1 CHAPTER 3 Working with Data Types and Operators.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Fall 2004CSI University of Ottawa Introduction to PHP Basic principles and syntax.
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,
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
2.1 The Part of a C++ Program. The Parts of a C++ Program // sample C++ program #include using namespace std; int main() { cout
PHP using MySQL Database for Web Development (part II)
Chapter Topics The Basics of a C++ Program Data Types
Chapter 6 JavaScript: Introduction to Scripting
CHAPTER 5 SERVER SIDE SCRIPTING
Basic Elements of C++.
* Lecture # 7 Instructor: Rida Noor Department of Computer Science
JavaScript: Functions.
PHP Introduction.
Basic Elements of C++ Chapter 2.
2.1 Parts of a C++ Program.
Introduction to C++ Programming
WEB PROGRAMMING JavaScript.
Introduction to C++ Programming
HYPERTEXT PREPROCESSOR BY : UMA KAKKAR
Chapter 2: Introduction to C++.
Data Types and Expressions
7 – Variables, Input and Output
Tutorial 10: Programming with javascript
23 PHP.
Presentation transcript:

1 PHP  Introduction to PHP  Basic Syntax of PHP Variables, Constant, Data Type, Type Casting  Getting Data From Client  PHP Database Manipulation

2 Introduction  PHP PHP: Hypertext Preprocessor Originally called “Personal Home Page Tools” Popular server-side scripting technology Open-source  Anyone may view, modify and redistribute source code  Supported freely by community Platform independent

3 Basic Syntax of PHP  Basic application Scripting delimiters   Must enclose all script code Variables preceded by $ symbol  Case-sensitive

4 Basic Syntax of PHP End statements with semicolon Comments  // for single line  /* */ for multiline Filenames end with.php by convention

5 Declare variable $name Scripting delimiters Single-line comment Function print outputs the value of variable $name

6 Basic Syntax of PHP Simple PHP program

7 Basic Syntax of PHP Variable  Variable –area of memory set aside to store information, and it is assigned a particular identifier by the programmer.  Begin with a dollar ‘$’ sign.  To assign a value to variable,use the equals sign or assignment ‘= ’ operator. $author = “William Shakespear”;

8 Basic Syntax of PHP  Case-sensitive : $author = “William Shakespear”; $Author = “William Shakespear”; Above codes actually create two separate variables

9 <? $actor=”Sean Connery”; echo $actor; ?>

10 Basic Syntax of PHP Data Types

11 Basic Syntax of PHP String Data Type  Holds textual information or words, and can even hold full sentences.  Everything stored inside quotation marks automatically becomes text, even numeric data. $CarType= “Cadillac”; $EngineSize=“2.6”;

12 Basic Syntax of PHP String Concatenation  The process of adding one string to another – example : Attach one string to the end of another.  Use.(period) as the concatenation operator. $Car= $CarType.$EngineSize; Cadillac2.6

13 Basic Syntax of PHP Numeric Data Type  Holds two different numeric data types- integers (whole numbers) & doubles (floating point numbers).  No quotation marks. $an_integer= 33; $another_integer = $a_double= 4.567; $another_double = -23.2

14 Basic Syntax of PHP Simple Mathematical Operations  Numerical operators can use to perform mathematical operations. +, *, -, /, % (8%5=3)

15 <?php $Salary = 15000; $TaxRate = 20; $Pension = 3; $BeforePensionIncome = $Salary - (($Salary / 100) * $TaxRate); $AfterPensionIncome = $BeforePensionIncome - (($BeforePensionIncome/100)*$Pension); echo "Before Pension Deductions:$BeforePensionIncome "; echo "After Pension Deductions:$AfterPensionIncome"; ?> </BODY

16

17 Basic Syntax of PHP Type Casting $NewVariable = 13; $NewVariable = (string) $NewVariable ; $NewVariable = 13; $NewVariable = (string) $NewVariable ; $NewVariable = (integer) $NewVariable ;

18 Basic Syntax of PHP gettype and settype  gettype()– to determine the current data type of variable. gettype($number);  To display : $number = 5; echo gettype($number); Output :integer  settype()– to specifically set the data type. $number = 10; settype($number, “string”);

19 Assign a string to variable $testString Assign a double to variable $testDouble Assign an integer to variable $testInteger

20 Print each variable’s value Call function settype to convert the data type of variable $testString to a double. Call function settype to convert the data type of variable $testString to an integer. Convert variable $testString back to a string

21 Use type casting to cast variable $data to different types

22 Type conversion

23 Basic Syntax of PHP Constants  An identifier, which takes a value that cannot be changed. The Define Keyword  Need a special keyword define.  Don’t need to be prefixed with a dollar sign.  Constant names are by convention all in upper case. define(“FREEZINGPOINTCENTIGRADE”, 0); Constant nameConstant value

24 Basic Syntax of PHP  Constant that contains text – enclose the constant value with quotation marks, example : define(“INDEPENDENCEDAY”, “31 st August”); define(“COUNTRY”, “Malaysia”);  You can use echo() to display constants on web pages.  You can also append them to text, by using the concatenate operator. echo “Independence Day is on”. INDEPENDENCEDAY ;

25 Basic Syntax of PHP  Always make sure that constant name appears outside the quotation marks. echo “Independence Day is on INDEPENDENCEDAY”; OUTPUT = Independence Day is the INDEPENDENCEDAY  PHP also has its own built-in constants, example: echo PHP_OS; (use to reflect values of OS that PHP is running on)

26 Getting Data From Client Notes can be obtained from:

27 PHP Database Manipulation  PHP supports for a wide range of databases.  The following databases are currently supported:  Adabas DInterBase  PostgreSQL  dBase  FrontBase  SQLite  Empress  mSQL  Solid  Direct MS-SQL  Sybase  Hyperwave  MySQL  Velocis  IBM DB2  ODBC  Unix dbm  Informix  Oracle (OCI7 and OCI8)  Ingres

28 What is MySQL?  MySQL is a small database server  MySQL is ideal for small and medium applications  MySQL supports standard SQL  MySQL compiles on a number of platforms  MySQL is free to download and use

29 Connecting to Database Connect Server <? $link = mysql_connect("localhost")or die("Connect Error: ".mysql_error()); print "Successfully connected.\n"; mysql_close($link); ?>

30 Inserting Data into Database form_insert_record.php Birthdays Insert Form Insert Record <? print "Enter name: \n";

31 Inserting Data into Database print "Enter Birthday: \n"; print " \n"; ?>

32 Inserting Data into Database insert.php <? $name=$_POST['name']; $birthday=$_POST['birthday']; $db="mydatabase"; $link = mysql_connect("localhost"); if (! $link) die("Couldn't connect to MySQL"); mysql_select_db($db, $link) or die("Couldn't open $db: ".mysql_error()); //mysql_query ("INSERT INTO birthdays (name, //birthday) VALUES ('Peggy', 'June4')"); mysql_query ("INSERT INTO birthdays (name, birthday) VALUES ('$name','$birthday')"); echo "Record Inserted"; mysql_close($link); ?>

33 Displaying Data from Database display.php (Title Here) <?php $db="mydatabase"; $link = mysql_connect("localhost"); if (! $link) die("Couldn't connect to MySQL"); mysql_select_db($db, $link) or die("Couldn't open $db: ".mysql_error()); $result = mysql_query( "SELECT * FROM birthdays" ) or die("SELECT Error: ".mysql_error()); $num_rows = mysql_num_rows($result);

34 Displaying Data from Database print "There are $num_rows records. "; print " \n"; while ($get_info = mysql_fetch_row($result)){ print " \n"; foreach ($get_info as $field) print "\t $field \n"; print " \n"; } print " \n"; mysql_close($link); ?>

35 Deleting Data from Database form_delete.php Birthdays Delete Form <? $db="mydatabase"; $link = mysql_connect("localhost"); if (! $link) die("Couldn't connect to MySQL"); mysql_select_db($db, $link) or die("Couldn't open $db: ".mysql_error()); $result = mysql_query( "SELECT * FROM birthdays" ) or die("SELECT Error: ".mysql_error()); $num_rows = mysql_num_rows($result);

36 Deleting Data from Database print "There are $num_rows records. "; print " \n"; while ($get_info = mysql_fetch_row($result)){ print " \n"; foreach ($get_info as $field) print "\t $field \n"; print " \n"; } print " \n"; mysql_close($link); ?>

37 Deleting Data from Database Enter Line Number to Delete:

38 Deleting Data from Database delete.php <? $id=$_POST['id']; $db="mydatabase"; $link = mysql_connect("localhost"); if (! $link) die("Couldn't connect to MySQL"); mysql_select_db($db, $link) or die("Couldn't open $db: ".mysql_error()); mysql_query("DELETE FROM birthdays WHERE id=$id"); echo "Record Updated"; mysql_close($link); ?>