TRAINING REPORT On
PHP Submitted for partial fulfillment Of B. Tech.
in COMPUTER SCIENCE AND ENGINEERING SUBMITTED TO: -
SUBMITTED BY:-
Er.Ankush
Hitender Dalal
(Lect in CSE/IT Deptt.)
1609068 th
CSE 4
(Affiliated to Kurukshetra University, Kurukshetra) (Approved by AICTE, New Delhi) 1
Year
CERTIFICATE I hereby certify that the work presented in this report entitled “PHP” submitted in the partial fulfillment of the requirement for the award of degree of Bachelor from Computer Science Engineering, from JIND INSTITUTE OF TECHNOLOGY,JIND and is an authentic record of my own work.
Hitender Dalal 1609068
2
ACKNOWLEDGEMENT With profound sense of gratitude, I take it as a highly esteemed privilege in expressing my sincere thanks to my supervisor and guide Miss SUMAN for her technical guidance, sound advice, excellent supervision, valuable suggestions and ever available help during entire course of training. Without her wise counsel and able guidance, this training would not have been completed in this manner. I owe my sincere gratitude to all the faculties of CSE Jind Institute of Engineering and Technology, Jind for their encouragement and unfailing interest in sincere suggestions from time to time in this work. Finally, I owe to the almighty who gave me to carry out this work with sincerity and dedication.
Hitender Dalal 1609068
3
TABLE OF CONTENTS 1. INTRODUCTION....................................................................................................6-7 1.1 HISTORY OF PHP..........................................................................................6 1.2 FEATURES OF PHP.......................................................................................7 2. HTML........................................................................................................................8-9 2.1 HYPERTEXT MARKUP LANGUAGE.......................................................8 2.2 TAGS IN HTML...............................................................................................8 2.3 FEATURES OF HTML...................................................................................9 2.4 BREAKS USED IN HTML.............................................................................9 3. KEY CONCEPTS OF HTML.................................................................................10-11 3.1 ELEMENTS.....................................................................................................10 3.2 TAGS................................................................................................................10 3.3 ATTRIBUTES NAD VALUES......................................................................10 3.4NESTING..........................................................................................................11 4. TAGS AND CODING...............................................................................................12-15 5. PHP.............................................................................................................................16-17 5.1 HYPERTEXT PRE-PROCESSOR................................................................16 6. CONTROL STRUCTURE IN PHP.........................................................................18-30 6.1 CONDITIONAL CONTROL STRUCTURE................................................18 6.2 UNCONDIONAL CONTROL STRUCTURE...............................................26 6.3 REPEATITION LOOPS...................................................................................28 7. $GET AND $POST VARIABLES.............................................................................31-32 7.1 $GET VARIABLE............................................................................................31 7.2 $POST VARIABLE...........................................................................................31 7.3 DIFFERENCE BETWEEN GET AND POST................................................32 8. SESSION , COOKIES AND FILE UPLOADING....................................................33-35 8.1 PHP SESSION VARIABLE...............................................................................33 8.2 STARTING A PHP SESSION............................................................................33 8.3 PHP COOKIE.......................................................................................................33 8.4 CREATING A PHP COOKIE............................................................................34 8.5 RETRIVING A COOKIE...................................................................................34 8.6 DELETING A COOKIE.....................................................................................34 8.7 PHP FILE UPLOADING....................................................................................35 8.8 CREATING AN UPLOAD FILE.......................................................................35
4
9. JAVASCRIPT...............................................................................................................36-37 9.1 INTRODUCTION TO JAVASCRIPT...............................................................36 9.2 JAVASCRIPT FORM VALIDATION...............................................................37 9.3 REQUIRED FEILDS............................................................................................37 10. CASCADING STYLE SHEETS (CSS).....................................................................38-39 10.1 INTRODUCTION TO CSS................................................................................38 10.2 STYLE SHEET...................................................................................................38 10.3 EXTERNAL STYLE SHEET............................................................................38 10.4 INTERNAL STYLE SHEET.............................................................................39 10.5 INLINE STYLES................................................................................................39 11. MySQL DATABASE...................................................................................................40-54 11.1 MySQL DATABASE..........................................................................................40 11.2 CONNECTING A DATABASE........................................................................44 11.3 PHP MySQL INSERT INTO.............................................................................45 11.4 PHP MySQL SELECT.......................................................................................48 11.5 DISPLAY RESULT IN AN HTML TABLE....................................................49 11.6 PHP MySQL THE WHERE CLAUSE.............................................................50 11.7 PHP MySQL ORDER BY KEYWORD............................................................51 11.8 PHP MySQL UPDATE.......................................................................................52 11.9 PHP MySQL DELETE.......................................................................................54 12. REFRENCES...................................................................................................................55
5
1. INTRODUCTION PHP stands for HYPERTEXT PRE-PROCESSOR . But It stands for HPP then why it still called PHP . We came to know about it in the history of PHP.
1.1 HISTORY OF PHP
PHP originally stands for Personal Home Page. PHP was developed by RASMUS LERDOOF in 1994 . He firstly use it for his personal use at home . In 1997 market name for PHP came HYPERTEXT PRE-PROCESSOR . First version of PHP (2.0) came in 1997 then . 3.0 came in 1999 . Latest version of PHP is 5.3.5 . In September of year 1994 , Rasmus expanded upon PHP and - for a short time - actually dropped the PHP name. Now referring to the tools as FI (short for "Forms Interpreter"), the new implementation included some of the basic functionality of PHP as we know it today . It had Perl-like variables, automatic interpretation of form variables, and HTML embedded syntax. The syntax itself was similar to that of Perl, albeit much more limited, simple, and somewhat inconsistent . The code got another complete makeover, and in April of 1996, combining the names of past releases, Rasmus introduced PHP/FI. This second-generation implementation began to truly evolve PHP from a suite of tools into a programming language in its own right. It included built-in support for DBM, mySQL, and Postgres95 databases, cookies, userdefined function support, and much more. That June, PHP/FI was given a version 2.0 status. An interesting fact about this, however, is that there was only one single full version of PHP 2.0. When it finally graduated from beta status in November, 1997, the underlying parsing engine was already being entirely rewritten . A Netcraft survey as of May, 1998, indicated that nearly 60,000 domains domains reported having headers containing "PHP," indicating that the host server did indeed have it installed. This number equated to approximately 1% of all domains on the Internet at the time. Despite these impressive figures, the maturation of PHP/FI was doomed to limitations; while there were several minor contributors, it was still primarily developed by an individual.
6
1.2 FEARTURES OF PHP It is very SIMPLE . Open source language . It have HTML embedded scripting . It is Server sided . In PHP we create COOKIES . In PHP we create SESSIONS . It have Object Oriented Programming Structure . It is Portable . SAFE MODE : The PHP safe mode is an attempt to solve the shared-server security problem. It is architecturally incorrect to try to solve this problem at the PHP level, but since the alternatives at the web server and OS levels aren't very realistic, many people, especially ISP's, use safe mode for now . DEALING WITH XFORMS : Xforms defines a variation on traditional webforms which allows them to be used on a wider variety of platforms and browsers or even nontraditional media such as PDF documents . The first key difference in XForms is how the form is sent to the client . It is used by millions of Websites today PHP can be used with all kind of DBMS . PHP is free . PHP files are saved with the extension .php in the server files .
SYNTAX OF PHP < ? php
?>
7
2. HTML 2.1 HYPER TEXT MARKUP LANGUAGE HYPER - non linear TEXT - any simple text MARKUP - tags and linking LANGUAGE - any language for programming. It is used to generate web page . HTML, an initialism of Hypertext Markup Language, is the predominant markup language for web pages. It provides a means to describe the structure of textbased information in a document — by denoting certain text as headings, paragraphs, lists, and so on.
2.2 TAGS IN HTML Tags are the keywords in angle brackets used for scripting in HTML Tags are of two types : Paired : Tags which have an opening and closing . for e.g.
Unpaired : Tags need not to be closed for e.g.
need not to be closed .
need not to be closed
8
2.3 FEATURES OF HTML Client sided language Not case sensitive Interpret language Easy to use and understand HTML is free Almost all browsers support HTML Most search engine friendly language Most development tool support HTML Basic language for Website designing Server free language It is Static . No site can be structured without the knowledge of HTML . Not much effective features can be added to the site if made only with HTML . No knowledge of programming is needed to do coding in HTML . HTML originally was developed with the intent of defining the structure of documents (headings, paragraphs, lists, and so forth) to facilitate the sharing of scientific information between researchers .
2.4 BREAKS USED IN HTML In HTML we use 3 types of breaks : 1. br :- It is an unpaired tag used for single line break . 2. p :- It is a paired tag and used for more than one line break . 3.   :- It stands for non-breaking space and it gives only one character space . It is not a tag .
9
3. KEY COCEPTS OF HTML The first step toward understanding and working with HTML is learning the basic terms that describe most of the functions of this language. You will come across these terms repeatedly as you use HTML and if you understand them, you will have progressed a long way toward comprehending HTML, not to mention XHTML.
3.1 ELEMENTS All HTML pages are made up of elements. Think of an element as a container in which a portion of a page is placed. Whatever is contained inside the element will take on the characteristics of that element. For example, to identify a heading on a page, you would enclose it in a heading element
. If you want to create a table, you put the table information inside the table element
. To construct a form, you need the form element
.
3.2 TAGS Often, you’ll find the terms element and tag used interchangeably. It’s fairly common, but not strictly accurate. An element is made up of two tags: an opening tag and a closing tag. Although it might seem somewhat picky to make this distinction, when you begin to work with XHTML (Extensible Hypertext Markup Language), it will be a very important difference to remember. If you get into the habit of distinguishing elements and tags from the very beginning, you’ll save yourself some confusion down the line. All tags are constructed the same way. The tag begins with a “less than” sign (<), then the element name, followed by a “greater than” sign (>). For example, an opening tag for the paragraph element would look like this:
. The only difference in a closing tag is that the closing tag includes a slash (/) before the element name:
. Your content goes between the tags. A simple paragraph might look like this:
This is an HTML paragraph.
Some elements do not use closing tags because they do not enclose content. These are called empty elements. For example, the line break element
does not require a closing tag. In the case of empty elements, add a closing slash after the element name, like this:
. When a browser sees the slash, it will recognize the element as one that does not need a separate, closing tag.
3.3 ATTRIBUTES AND VALUES Attributes are another important part of HTML markup. An attribute is used to define the characteristics of an element and is placed inside the element’s opening tag. For example, to specify the size of an image or graphic on your page, you would use the image element
along with the height and width attributes:
10
Be sure to notice that an equals sign and a set of quotation marks follow both the height and the width attributes. That’s because attributes need values to go with them. In the case of the preceding illustration, you might add a value of 200 to cause your image to display at a size of 200 x 200 pixels:
values work together with attributes to complete the definition of an element’s characteristics. An easy way to think of how attributes and values work together is to compare them with nouns and adjectives. A noun names something; an adjective describes it. An attribute names a characteristic; a value describes it. Imagine that you are trying to identify a person’s hair color with a markup language. Hair would be the element, color the attribute, and red the value. You might write such a description as follows:
Red-headed Person
3.4 NESTING Often you will want to apply more than one element to a portion of your page. An essential concept to understand is nesting. Nesting simply means that elements must never overlap. Properly nested elements are contained inside one another, as in the following:
Sometimes it’s easier to understand the concept if the elements are displayed vertically, like this:
The following elements, on the other hand, are overlapping:
Web browsers displaying an HTML page can be pretty forgiving if your elements are not properly nested; however, overlapped elements can create garbled results, particularly if you are trying to construct frames or tables. Also, when you become familiar with XHTML’s stricter standards, you’ll discover that overlapping elements are an absolute “no-no.”
11
4. TAGS AND CODING : It is the main starting tag in HTML . All the coding of the webpage is done in this tag .
: It displays the name or title of the Webpage . : It stands for heading and is used for giving the heading in the Webpage . : All the scripting of the content of the Webpage is mainly done in this tag .
to : These are tags in which we script our text . These are 6 tags in which h1 has the biggest font and h6 has the smallest .