php Mr. Amit Patel Hypertext Preprocessor Dept. of I.T.

Similar documents
What is PHP? [1] Figure 1 [1]

PHP 5 Introduction. What You Should Already Know. What is PHP? What is a PHP File? What Can PHP Do? Why PHP?

Princess Nourah bint Abdulrahman University. Computer Sciences Department

Chapter 7:- PHP. Compiled By:- Sanjay Patel Assistant Professor, SVBIT.

Web Engineering (Lecture 08) WAMP

PHP Introduction. Some info on MySQL which we will cover in the next workshop...

Web Application Development (WAD) V th Sem BBAITM(Unit-1) By: Binit Patel

PHP by Pearson Education, Inc. All Rights Reserved.

Part 3: Online Social Networks

Let's Look Back. We talked about how to create a form in HTML. Forms are one way to interact with users

AN INTRODUCTION TO WEB PROGRAMMING. Dr. Hossein Hakimzadeh Department of Computer and Information Sciences Indiana University South Bend, IN

Unit IV- Server Side Technologies (PHP)

SEEM4570 System Design and Implementation. Lecture 6 Game Part II

INTERNET PROGRAMMING. Software Engineering Branch / 4 th Class Computer Engineering Department University of Technology

The PHP language. Teaching you everything about PHP? Not exactly Goal: teach you how to interact with a database via web

Princess Nourah bint Abdulrahman University. Computer Sciences Department

URLs and web servers. Server side basics. URLs and web servers (cont.) URLs and web servers (cont.) Usually when you type a URL in your browser:

PHP. M hiwa ahamad aziz Raparin univercity. 1 Web Design: Lecturer ( m hiwa ahmad aziz)

CSC Web Programming. Introduction to JavaScript

Server side basics CS380

PHP Development - Introduction

IELM 511 Information Systems Design Labs 5 and 6. DB creation and Population

Introduction of PHP Created By: Umar Farooque Khan

Hello everyone! Page 1. Your folder should look like this. To start with Run your XAMPP app and start your Apache and MySQL.

What is Java Script? Writing to The HTML Document. What Can JavaScript do? CMPT 165: Java Script

Lecture 12. PHP. cp476 PHP

PHP. Introduction. PHP stands for PHP: Hypertext Preprocessor PHP is a server-side scripting language, like ASP PHP scripts are executed on the server

Web Programming. Dr Walid M. Aly. Lecture 10 PHP. lec10. Web Programming CS433/CS614 22:32. Dr Walid M. Aly

Important Points about PHP:

MULTIMEDIA AND WEB TECHNOLOGY

Web Engineering (Lecture 09) PHP part I

3 The Building Blocks: Data Types, Literals, and Variables

Lecture 7 PHP Basics. Web Engineering CC 552

PHP BASICS BY ALL-TECH SYSTEMS & CO

PHP 1. Introduction Temasek Polytechnic

Getting started 7. Performing operations 25

CS 377 Database Systems. Li Xiong Department of Mathematics and Computer Science Emory University

MULTIMEDIA AND WEB TECHNOLOGY

Course Syllabus. Course Title. Who should attend? Course Description. PHP ( Level 1 (

PHP INTERVIEW QUESTION-ANSWERS

Chapter 13 : Informatics Practices. Class XI ( As per CBSE Board) SQL Commands. New Syllabus Visit : python.mykvs.in for regular updates

What is MySQL? [Document provides the fundamental operations of PHP-MySQL connectivity]

Web Scripting using PHP

Database Connectivity using PHP Some Points to Remember:

CSCB20 Week 8. Introduction to Database and Web Application Programming. Anna Bretscher* Winter 2017

PHP. Interactive Web Systems

Programming for the Web with PHP

JavaScript s role on the Web

PHP 5 if...else...elseif Statements

C++ Programming: From Problem Analysis to Program Design, Third Edition

Web Systems Nov. 2, 2017

JavaScript CS 4640 Programming Languages for Web Applications

LECTURE 02 INTRODUCTION TO C++

Server side basics CSC 210

PHP and MySQL for Dynamic Web Sites. Intro Ed Crowley

Web Application Development (WAD) V th Sem BBAITM (Unit 4) By: Binit Patel

CS6501 IP Unit IV Page 1

SQL Commands & Mongo DB New Syllabus

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University

Setting Up a Development Server What Is a WAMP, MAMP, or LAMP? Installing a WAMP on Windows Testing the InstallationAlternative WAMPs Installing a

COMS W3101: SCRIPTING LANGUAGES: JAVASCRIPT (FALL 2017)

JavaScript CS 4640 Programming Languages for Web Applications

In addition to the primary macro syntax, the system also supports several special macro types:

An introduction for the novice. David Lawrence, JLab. 5/8/07 MySQL David Lawrence 1/36

B. V. Patel Institute of BMC & IT 2014

DevShala Technologies A-51, Sector 64 Noida, Uttar Pradesh PIN Contact us

COMP284 Scripting Languages Lecture 14: JavaScript (Part 1) Handouts

Course Topics. The Three-Tier Architecture. Example 1: Airline reservations. IT360: Applied Database Systems. Introduction to PHP

Basic PHP. Lecture 19. Robb T. Koether. Hampden-Sydney College. Mon, Feb 26, 2108

DR B.R.AMBEDKAR UNIVERSITY B.Sc.(Computer Science): III Year THEORY PAPER IV (Elective 4) PHP, MySQL and Apache

Core PHP. PHP output mechanism. Introducing. Language basics. Installing & Configuring PHP. Introducing of PHP keywords. Operators & expressions

Database Management Systems,

CS313D: ADVANCED PROGRAMMING LANGUAGE

CMPS 401 Survey of Programming Languages

CGS 3066: Spring 2015 JavaScript Reference

Databases on the web

ISSN: [Kumar * et al., 7(3): March, 2018] Impact Factor: 5.164

CISC 1600 Lecture 2.4 Introduction to JavaScript

Chapter 1 An introduction to relational databases and SQL

BASIC ELEMENTS OF A COMPUTER PROGRAM

PHP Hypertext Preprocessor

CS201- Introduction to Programming Latest Solved Mcqs from Midterm Papers May 07,2011. MIDTERM EXAMINATION Spring 2010

tablename ORDER BY column ASC tablename ORDER BY column DESC sortingorder, } The WHERE and ORDER BY clauses can be combined in one

CERTIFICATE IN WEB PROGRAMMING

Mount Saint Mary College, Newburgh, NY Internet Programming III - CIT310

Basic program The following is a basic program in C++; Basic C++ Source Code Compiler Object Code Linker (with libraries) Executable

PHP: The Basics CISC 282. October 18, Approach Thus Far

7/8/10 KEY CONCEPTS. Problem COMP 10 EXPLORING COMPUTER SCIENCE. Algorithm. Lecture 2 Variables, Types, and Programs. Program PROBLEM SOLVING

Manju Muralidharan Priya. CS4PM Web Aesthetics and Development WEEK 11

A.A. 2008/09. Why introduce JavaScript. G. Cecchetti Internet Software Technologies

Mysql Tutorial Show Table Like Name Not >>>CLICK HERE<<<

Introduction to programming with Python

Stored procedures - what is it?

WINTER. Web Development. Template. PHP Variables and Constants. Lecture

Open Source Web Application Development - CS310

BIT Java Programming. Sem 1 Session 2011/12. Chapter 2 JAVA. basic

Introduction to Databases and SQL

Alan Forbes - The Joy of PHP 1

SEEM4570 System Design and Implementation Lecture 03 JavaScript

What we will do today Explain and look at examples of. Programs that examine data. Data types. Topic 4. variables. expressions. assignment statements

Transcription:

php Hypertext Preprocessor Mr. Amit Patel Dept. of I.T..com.com

PHP files can contain text, HTML, JavaScript code, and PHP code PHP code are executed on the server, and the result is returned to the browser as plain HTML What is a PHP File? PHP files have a default file extension of ".php".com

What Can PHP Do? PHP can generate dynamic page content. PHP can create, open, read, write, and close files on the server. PHP can collect form data. PHP can send and receive cookies. PHP can add, delete, modify data in your database. PHP can restrict users to access some pages on your website. PHP can encrypt data. With PHP you are not limited to output HTML. You can output images, PDF files, and even Flash movies. You can also output any text, such as XHTML and XML..com

Why PHP? PHP runs on different platforms (Windows, Linux, Unix, Mac OS X, etc.) PHP is compatible with almost all servers used today (Apache, IIS, etc.) PHP has support for a wide range of databases PHP is free. Download it from the official PHP resource: www.php.net PHP is easy to learn and runs efficiently on the server side.com

<html> <body> <h1>my first PHP page</h1> <?php echo Welcome Alpha!";?> </body> </html> Basic PHP Syntax A PHP script starts with <?php and ends with?>:.com

<!DOCTYPE html> <html> <body> Comment in PHP <?php //This is a PHP comment line /* This isa PHP comment block*/?> </body> </html>.com

Rules for Variables in PHP As with algebra, PHP variables can be used to hold values (x=5) or expressions (z=x+y). Variable can have short names (like x and y) or more descriptive names (age, carname, totalvolume). Rules for PHP variables: A variable starts with the $ sign, followed by the name of the variable A variable name must begin with a letter or the underscore character A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ ) A variable name should not contain spaces Variable names are case sensitive ($y and $Y are two different variables).com

<?php $x=5; $y=6; $z=$x+$y; echo $z;?> x=5 y=6 z=x+y Variables in PHP In algebra we use letters (like x) to hold values (like 5). From the expression z=x+y above, we can calculate the value of z to be 11. In PHP these letters are called VARIABLES..com

PHP is a Loosely Typed Language $txt="hello world!"; $x=5; PHP automatically converts the variable to the correct data type, depending on its value. In a strongly typed programming language, we will have to declare (define) the type and name of the variable before using it..com

PHP Variable Scopes PHP has four different variable scopes: Local scope Global scope Static scope Parameter scope.com

<?php $x=5; // global scope Local Scopes function mytest() echo $x; // local scope mytest(); echo $x;?>.com

Global Scopes <?php $x=5; // global scope $y=10; // global scope function mytest() global $x,$y; $y=$x+$y; mytest(); echo $y; // output is 15?>.com

<?php function mytest() static $x=0; echo $x; $x++; mytest(); mytest(); mytest();?> Static Scopes.com

<?php function mytest($x) echo $x; mytest(5);?> Parameter Scopes A parameter is a local variable whose value is passed to the function by the calling code. Parameters are declared in a parameter list as part of the function declaration:.com

String Variables in PHP String variables are used for values that contain characters. After we have created a string variable we can manipulate it. A string can be used directly in a function or it can be stored in a variable. In the example below, we create a string variable called txt, then we assign the text "Hello world!" to it. Then we write the value of the txt variable to the output: <?php $txt="hello world!"; echo $txt;?>.com

Concatenation String Operators There is only one string operator in PHP. The concatenation operator [. ] is used to join two string values together. <?php $txt1="hello world!"; $txt2="what a nice day!"; echo $txt1. " ". $txt2;?>.com

PHP strlen() function Sometimes it is useful to know the length of a string value. The strlen() function returns the length of a string, in characters. <?php echo strlen("hello world!");?>.com

PHP strpos() function The strpos() function is used to search for a character or a specific text within a string. If a match is found, it will return the character position of the first match. If no match is found, it will return FALSE. <?php echo strpos("hello world!","world");?>.com

PHP Date() function <?php print( Today s Date is.date( l F d, y ));?>.com

PHP Arithmetic Operators.com

PHP Assignment Operators The basic assignment operator in PHP is "=". It means that the left operand gets set to the value of the expression on the right. That is, the value of "$x = 5" is 5..com

PHP Incr/Decr Operators.com

PHP Comparison Operators.com

PHP Logical Operators.com

PHP Array Operators.com

PHP If Statements SYNTAX: if (condition) code to be executed if condition is true; <?php $t=date("h"); if ($t<"20") echo "Have a good day!";?>.com

SYNTAX: PHP If Else Statements if (condition) code to be executed if condition is true; else code to be executed if condition is false;.com

PHP If Else Statements (cont ) <?php $t=date("h"); if ($t<"20") echo "Have a good day!"; else echo "Have a good night!";?>.com

SYNTAX: PHP If Else If Else Statements if (condition) code to be executed if condition is true; else if (condition) code to be executed if condition is true; else code to be executed if condition is false;.com

PHP If Else If Else Statements (cont ) <?php $t=date("h"); if ($t<"10") echo "Have a good morning!"; else if ($t<"20") echo "Have a good day!"; else echo "Have a good night!";?>.com

SYNTAX: PHP Switch Case Statements switch (n) case label1: code to be executed if n=label1; break; case label2: code to be executed if n=label2; break; default: code to be executed if n is different from both label1 and label2;.com

PHP Switch Case Statements <?php $favcolor="red"; switch ($favcolor) case "red": echo "Your favorite color is red! ; break; case "blue": echo "Your favorite color is blue! ; break; case "green": echo "Your favorite color is green! ; break; default: echo "Your favorite color is None of them!";?>.com

PHP Arrays An array is a special variable, which can hold more than one value at a time. 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="volvo"; $cars2="bmw"; $cars3="toyota"; An array can hold many values under a single name, and you can access the values by referring to an index number..com

Creating a php Arrays PHP Arrays In PHP, the array() function is used to create an array: Types of php Arrays In PHP, there are three types of arrays: Indexed arrays - Arrays with numeric index Associative arrays - Arrays with named keys Multidimensional arrays - Arrays containing one or more arrays.com

PHP Indexed Arrays There are two ways to create indexed arrays: The index can be assigned automatically (index always starts at 0): $cars=array("volvo","bmw","toyota"); The index can be assigned manually: $cars[0]="volvo"; $cars[1]="bmw"; $cars[2]="toyota"; <?php $cars=array("volvo","bmw","toyota"); echo "I like ". $cars[0]. ", ". $cars[1]. " and ". $cars[2]. ".";?>.com

PHP Associative Arrays Associative arrays are arrays that use named keys that you assign to them. There are two ways to create an associative array: $age=array("peter"=>"35","ben"=>"37","joe"=>"43"); $age['peter']="35"; $age['ben']="37"; $age['joe']="43"; <?php $age=array("peter"=>"35","ben"=>"37","joe"=>"43"); echo "Peter is ". $age['peter']. " years old.";?>.com

What is MySQL? PHP Database Connectivity MySQL is a database system used on the web MySQL is a database system that runs on a server MySQL is ideal for both small and large applications MySQL is very fast, reliable, and easy to use MySQL supports standard SQL MySQL compiles on a number of platforms MySQL is free to download and use MySQL is developed, distributed, and supported by Oracle Corporation MySQL is named after co-founder Monty Widenius's daughter: My.com

Open a Connection to the MySQL Server Before we can access data in a database, we must open a connection to the MySQL server. In PHP, this is done with the mysqli_connect() function. Syntax PHP Database Connectivity mysqli_connect(host,username,password,dbname);.com

PHP Database Connectivity.com

PHP Database Connectivity Open a Connection to the MySQL Server <?php // Create connection $con=mysqli_connect( localhost, root, ", temp ); // Check connection if (mysqli_connect_errno($con)) echo "Failed to connect to MySQL: ". mysqli_connect_error();?>.com

PHP Database Connectivity Close a Connection to the MySQL Server <?php $con=mysqli_connect( localhost", root,, temp ); // Check connection if (mysqli_connect_errno($con)) echo "Failed to connect to MySQL: ". mysqli_connect_error(); mysqli_close($con);?>.com

PHP Database Connectivity Create a Database <?php $con=mysqli_connect( localhost, root, abc123 ); // Check connection if (mysqli_connect_errno()) echo "Failed to connect to MySQL: ". mysqli_connect_error(); // Create database $sql="create DATABASE temp"; if (mysqli_query($con,$sql)) echo "Database my_db created successfully"; else echo "Error creating database: ". mysqli_error();?>.com

Create a Table PHP Database <?php $con=mysqli_connect( localhost","peter","", temp"); // Check connection if (mysqli_connect_errno()) echo "Failed to connect to MySQL: ". mysqli_connect_error();.com

PHP Database // Create table $sql="create TABLE persons(firstname CHAR(30),Lastname CHAR(30),Age INT)"; // Execute query if (mysqli_query($con,$sql)) echo "Table persons created successfully"; else echo "Error creating table: ". mysqli_error();?>.com

Primary Keys and Auto Increment Fields PHP Database Each table in a database should have a primary key field. The following example sets the PID field as the primary key field. The primary key field is often an ID number, and is often used with the AUTO_INCREMENT setting. AUTO_INCREMENT automatically increases the value of the field by 1 each time a new record is added. To ensure that the primary key field cannot be null, we must add the NOT NULL setting to the field: $sql = "CREATE TABLE Persons ( PID INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(PID), Firstname CHAR(15), Lastname CHAR(15), Age INT(3) )";.com

Inserting Data into the Table PHP Database <?php $con=mysqli_connect( localhost", root,, temp"); // Check connection if (mysqli_connect_errno()) echo "Failed to connect to MySQL: ". mysqli_connect_error(); mysqli_query($con,"insert INTO Persons (FirstName, LastName, Age)VALUES ('Peter', 'Griffin',35)"); mysqli_query($con,"insert INTO Persons (FirstName, LastName, Age) VALUES ('Glenn', 'Quagmire',33)"); mysqli_close($con);?>.com

Yet I will Not Consider this Presentation 100%. New Topic will be added at the end of the Slide after the Mid Sem Examination. By Mr. Amit Patel.com