p 7. Web Programming Module
p 7. Web Programming Module
BONGA UNIVERSITY
JUANUARY, 2022
Chapter 1: Introduction
Chapter Description
This chapter deals with the Overview of Internet, website, webpage, types of website
(Static vs. dynamic), webpage design tools, World Wide Web, client-server
architecture and web server architecture, Web Hosting and Domain Name
Registration. To deliver these contents active learning methods such as brain storming,
interactive lecture, group discussion and independent learning will be used and assess
students ‘achievement, continuous assessments such as quiz, test, class activities,
assignments and others will be used.
The history of the Internet dates back to the Cold War days of the late 1950s. It
evolved when the US Defense Force began to investigate a method of geographically
dispersing their centralized computer system. It was believed that reducing reliance on
one single route for transmission of data and using decentralized system, would
provide a safer option for controlling their missiles. This idea was a safe guard to
protect the flow of communications in the event of a major interruption. A 'fear' that in
the event of a nuclear war, an enemy may destroy a link in the US chain of
communications, was the precursor to the technology revolution!
Today, the internet is an international forum for exchange of information and ideas
between millions of people worldwide, a rapidly growing information super-highway.
In contrast, two decades prior to this, it was known mainly to those involved in the
military or academia.
Q. Define the following basic terms Web Browser, Website, Types of website
,webpage, Webpage design tools, Home Page, and Sub Pages, Social Media or Social
Networking Internet, Internet Access Provider or Internet Service Provider (ISP) –
and Interactive Forms.
• All the computers in the Web can communicate with each other.
• Web clients view the pages with a program called a Web browser.
Q. Explains in detail world wide web, web client, web server, and HTTP.
A web server can usually handle multiple simultaneous connections and—when not
communicating with a client—spends its time listening for an incoming connection
request. When one arrives, the server sends back a response to confirm its receipt.
4. The request crosses the Internet and arrives at the server.com web server.
5. The web server, having received the request, looks for the web page on its hard disk.
6. The server retrieves the web page and returns it to the browser.
Q. Explains how the user fetch the required information from the server and
illustrate with its architecture. Compare and Contrast
1. Web Hosting Vs. Domain Name Registration?
2. The Internet vs. World Wide Web
Chapter 2: Hyper Text Markup Language (HTML)
Chapter Description
This chapter deals with Web page Design and development using HTML, information
Architecture & visualization, Hyper Text Markup Language and CSS. To deliver these
contents active learning methods such as brain storming, interactive lecture, group discussion
and independent learning will be used and access students ‘achievement, continuous
assessments such as quiz, test, class activities, assignments and others will be used.
2.1 Web page Design and development
✓ Hierarchical Structure
✓ Hypertext Structure
✓ Database Structure
Make it Flexible
Consistent wording
Drop-down lists
Layout the Web Pages
Browser Display
Monitor Resolution
Functionality Testing
Usability Testing
As for any systems development project, you need to first find out what are the
requirements for the web site.
This means asking and getting answers to questions such as:
The purpose and goals of the web site should be agreed with the customer or
owner of the web site.
There will usually be a lot of information available to put on the web site.
It is necessary to sort through this information and select what is important and
necessary to go on the site.
It also needs to be organized into a structure that makes sense to the end user of the
web site.
Alphabetical
Chronological
Geographical
Q. Explain in detail about web development requirements, structures, hierarchies, web
page layouts, and web contents.
A well-organized site will help your users find key information quickly. It also will make
the experience of using your website more coherent, intuitive and satisfying. Additionally,
intuitively organized information architecture will help to ensure that all of the phases of your
website development run smoothly and efficiently. In fact, it can prevent time-consuming and
costly alterations to your visual design and site development by identifying required features,
the number and location of navigational links and the placement of content early in the
process.
If your site is being built in a content management system that allows editors to add their
own pages, the site may grow quickly, sometimes in confusing ways.
Static Web pages display the exact same information whenever anyone visits it. Static Web
pages do not have to be simple plain text. They can feature detailed multimedia design and
even videos. However, every visitor to that page will be greeted by the exact same text,
multimedia design or video every time he visits the page until you alter that page's source
code.
Dynamic Web Pages
Dynamic Web pages are capable of producing different content for different visitors from the
same source code file. The website can display different content based on what operating
system or browser the visitor is using, whether she is using a PC or a mobile device, or even
the source that referred the visitor. A dynamic Web page is not necessarily better than a static
Web page.
2.3 Hyper Text Markup Language (HTML)
A markup language, i.e. it‘s used to markup content. HTML is composed of several
tags.
HTML is the standard markup language for creating Web pages.
HTML Document:-
a. A text document containing markup tags
b. The tags tell the browser how to display the document
c. Should have an .htm or .html file name extension
d. Can be created using a simple text editor
An HTML document has the following basic structure:
<html>
<head>
<title>page title</title>
</head>
<body> here is the content
</body>
</html>
▪ The HTML document itself begins with <html> and ends with </html>.
▪ The visible part of the HTML document is between <body> and </body>.
▪ Tag names are enclosed in < and > and Commonly have the first tag in a pair is
a start tag and the second tag is the end tag
▪ The end tag is written like the start tag, but with a forward slash inserted before
the tag name
→Start tag format: <tag_name>
→End tag format: </tag_name> [note the / after <]
E.g. <strong>bold text</strong>
▪ Some tags may not have end tags E.g. <br>
▪ Tags may have attributes
Format: <p>…</p>
E.g. <p>this is a paragraph of text. it has a new line before and after it.</p>
The browser inserts a new line before and after the text in the paragraph tag.
Attribute:
align= “alignment” {left, right, center, justify}
line break - inserts a new line.
Format: <br>. E.g. Line one <br> line two <br> line three <br> line four
horizontal rule - inserts a horizontal line
Format: <hr>
E.g. <hr width= “75%” noshade color= “#FF0000”>
sub/sup - define either a subscript or a superscript
Format: <sub>…</sub> ; <sup>…</sup>
E.g.
X<sub>1</sub><sup>2</sup> + 2X<sub>3</sub>
Q. Add paragraph by using paragraph tags in the above question and read
the attributes of HTML tags?
2.3.3 Lists
HTML lists are defined with the <ul> (unordered/bullet list) or the
<ol> (ordered/numbered list) tag, followed by <li> tags (list items) as well as
definition Lists <dl> followed by <dt> and <dd> :
I. Unordered Lists (ul) - define bulleted lists
Format: <ul>
<li>…</li>
<li>…</li>…
</ul>
Attribute:
type= “bullet type” {disc, circle, square}
E.g. <ul type= “square”>
<li>book</li><li>marker</li><li>chalk</li></ul>
II. Ordered Lists (ol) - define numbered lists
Format: <ol>
<li>…</li>
<li>…</li>…
</ol>
Attribute: type= “number type” {1, i, I, a, A}
E.g. <ol type= “I”> <li>book</li><li>marker</li><li>chalk</li></ol>
III. Definition Lists (dl) - define a list of term-description pairs
Format : <dl>
<dt>…</dt>
<dd>…</dd>
<dt>…</dt>
<dd>…</dd>
</dl>
E.g. <dl>
<dt>book</dt><dd>something that we read …</dd>
<dt>marker</dt><dd>something we write with …</dd>
</dl>
Q. Write the following sentence by using ordered list, unordered list and
definition lists?
Bonga university College of Engineering and Technology departments
are:
1. Computer science
2. Electrical engineering
• Communication engineering
• Power engineering
• Control engineering
2.3.4 Images - insert images in an html document which are defined with
the <img> tag
If not specified, the browser expects to find the image in the same folder as the web
page.
However, it is common to store images in a sub-folder. You must then include the
folder name in the src attribute:
Example:
2.3.5 Anchor - defines a hyperlink or a named anchor and is used for navigation.
HTML links are defined with the <a> tag. The link address is specified in
the href attribute:
Format: <a>…</a>
E.g. <a href= “home.htm”>Go to home</a>
<a href= “http://www.google.com” target=“_blank”>Google</a>
Q. Discuss the html code in detail how can add your image, link such as
website to your page and read in detail the attributes of image, and anchor
in the reference book?
Output
Divisions - In HTML, we can create divisions of an HTML document using the <div>
tag.
A <div> is a logical block tag that has no predefined meaning or rendering. It is also
very important for page layout design and works well with CSS.
Tag format: <div> … </div>
Attributes:
Align= “alignment” {left, right, center} - define content alignt.
Type Description
<input type="number"> Defines a one-line number input field only but it doesn’t
support text.
<input type="datetime- Used to define and insert a one-line yy/mm/dd and time
local"> with minute input field
<input type="radio"> Defines a radio button (for selecting one of many choices)
<input type="checkbox"> Defines a Checkbox button (for selecting one of many choices)
The form data can be sent in two methods: GET & POST
➢ GET Method
✓ Used for submit small and non-secure data it is the default method
✓ Never use GET to send sensitive data! (will be visible in the URL)
✓ Data is sent as part of the request URL
✓ Limitation in size of data (The length of a URL is limited (about 3000
characters)
✓ Used for submit large & secure data
✓ Input is sent as a data stream after the request URL
✓ Useful for form submissions where a user want to bookmark the result
✓ GET is better for non-secure data, like query strings in Google
➢ POST Method
Frames divide a browser window into several pieces or panes, each pane containing a
separate XHTML page.
One of the key advantages that frames offer is that you can then load and reload single
panes without having to reload the entire contents of the browser window.
First you need the <frameset> element, which is used instead of the <body> element.
The frameset defines the rows and columns your page is divided into, including where
each individual frame will go.
Q. Read and discuss the frameset attribute elements such as cols , border , frame
spacing src, margin width and height ,no resize and no frame it‘s advantage and
examples for each?
2.3.8.1 Creating Links between Frames
The most popular uses of frames is to place navigation bars in one frame and
then load the pages with the content into a separate frame. This is particularly
helpful in three situations:
Chapter 3
CSS stands for cascading style sheets. Styles define how to display HTML elements
and are normally stored in style sheets.
Html tags were originally designed to define the content of a document. They were
supposed to say “this is a paragraph”, “this is a table”… by using tags like
<p>, <table>…. The layout of the document was supposed to be taken care of by the
browser, without any formatting tags.
Syntax:
Selector { property:value;}
Where
Selector – the html element or tag you wish to define and to be affected by the rule.
Property – the attribute you wish to define its value.
Value – the corresponding value to the attribute to the left.
.1 Selector
There are many ways to write selectors for cascading style sheets.
1. Type selector
2. Universal selector
3. Class selector
4. Id selector
5. Grouping selectors
Q. Read in detail the above ways of selectors it‘s definition, advantage, syntax and examples
for each?
2 CSS Properties
Cascading style sheet properties can be classified into seven broad categories.
Background properties:-CSS background properties define the background effects of
elements.
Text properties:-These properties allow you to control the appearance of text in your
document
Font properties: - The font properties allow you change the font family, boldness,
size and the style of a text.
Border properties: - These properties allow you to specify the style, color and
width of an element’s border.
Q. Read in detail the format and examples of CSS properties such as background, text,
font, border margins, padding and list?
1. Inline styles
An inline style loses many of the advantages of style sheets by mixing content with
presentation. Use this method sparingly when you need a style to be applied to a single
occurrence of an element.
To use inline styles you use the style attribute in the relevant tag. The style attribute
can contain any CSS property.
2. Internal styles
This type of style sheet should be used when a single document has a unique style.
You define internal styles in the head section by using the <style> tag.
e.g <head>
<style>
H1 { color:yellow;
Text-align:left; }
P{ margin-left:20px; }
</style>
</head>
3. External style sheets
An external style sheet is used when the style is applied to many pages. With an
external style sheet you can change the look of an entire website by changing one file
(the style sheet). Each page should be linked to the style sheet using the <link> tag
inside the head section.
e.g assume the style sheet is saved with a file name style.css.
##Style.css
Body{ margin:0px; }
Td{ font-1px Vedanta Arial Helvetica;
Color#003366; }
A{ color #FF6600;
Font-weight: bold; }
Q. read the following CSS contents from the reference book and from Internet.
➢ Value Inheritance
➢ percent
➢ Font-size Keywords
➢ Color Units
➢ Style Inheritance
➢ Measurement units
➢ Introduction to XML
Chapter Four
Client-Side Scripting Language
Chapter description
This chapter deals with the Overview of Script, identifiers, variables, reserved
words, conditional statements and function of java script, java script objects and event
handlers. To deliver these contents active learning methods such as brain storming,
interactive lecture, group discussion and independent learning will be used and assess
students ‘achievement, continuous assessments such as quiz, test, class activities,
assignments and others will be used.
Scripts on the web can be executed either at the client-side or at the server side.
Client side scripts are those scripts which are sent to the client from the server and
executed on the client‘s machine (by the web browser) I.e. the client side script code is
sent from the server to the client. While in the case of server-side scripts, the script
code is executed on the server and the result (if any) is sent to the client. There are
several client-side scripting languages:
The first character should me a letter, an underscore (_) or a dollar sign. Subsequent
character can be a letter, digit, underscore or a dollar sign. Valid identifier examples
Reserved words break do if switch type of case else in this var catch false
instance of the row void continue finally new true while default for null try with
delete function return.
Data types and variables
Numbers: integer, floating point, hexadecimal, octal.
Strings , Boolean ,objects and array
Variable declaration
Syntax: var identifier [ = initial_value ]
e.g. var x; var first_name
= „Abebe‘;
Q. Read the arithmetic, assignment, comparison and logical operators in the
reference book.
2. Switch
Looping
Often when you write code, you want the same block of code to run over and over
again in a row.
Instead of adding several almost equal lines in a script we can use loops to perform a
task like this. There are three types of loops for this purpose.
1. for loop
2. While loop
3. Do … while loop
Functions
syntax:
Statements
[return value]
1. Using the <script> tag in the <head>part of the html page. Example
<head>
<script>
</script>
</head>
2. Using the <script> tag and including an external JavaScript file.
3. Anywhere in the HTML document.
JavaScript objects
Properties are the values associated with an object. In the following example we are
using the length property of the String object to return the number of characters in a
string:
Methods
Methods are the actions that can be performed on objects.
Example:
<script
type="text/javascript">
var str="Hello world!";
document.write(str.toUpperCase());
</script>
In the above example we are using the to UpperCase() method of the String object to
display a text in uppercase letters:
1) The document objects
In the document object, you’ll find all functions and variables that have to do with
HTML documents. The examples of this object are used to adjust:
-Colors in a document
Using JavaScript, you can access the color settings of HTML documents. Elements
you
can change include the text color, background color, and the colors of not yet visited,
already visited, and active links.
1. Document.forms.elemetns
2) The string object
3. the data object
Q. Read in detail the above elements of java scripts in the reference book?
Every element on a web page has certain events which can trigger a JavaScript. For
example, we can use the on Click event of a button element to indicate that a function
will run when a user clicks on the button. We define the events in the HTML tags.
Event handlers
Commands that are incorporated into the HTML source code and that carry out a
predefined function or command given particular actions – are called event handlers.
All event handlers begin with on.... 1. onLoad event handler
2. onUnload
3. onMouseOver
4. onMouseOut
5. onFocus
6. onBlur
7. onChange
8. onClick
9. onSubmit
Q. Read in detail and give example for each of the above event handlers in reference
book?
Chapter 5
This chapter deals with the Overview of PHP, reasons to love PHP, adding PHP to
HTML, Syntax , variables and expressions, control statements and functions, the
information pass b/n pages, PHP MYSQL functions and form validation in PHP. To
deliver these contents active learning methods such as interactive lecture, group
discussion and independent learning will be used and assess students‘ achievement,
continuous assessments such as quiz, test, class activities, assignments and others will
be used.
PHP is the Web development language written by and for Web developers.
PHP stands for PHP: Hypertext Preprocessor. The product was originally
named Personal Home Page Tools, and many people still think that’s what the
acronym stands for. But as it expanded in scope, a new and more appropriate
(albeit GNU-is highly recursive) name was selected by community vote. PHP
is a server-side scripting language, which can be embedded in HTML or used
as a standalone binary (although the former use is much more common).
Proprietary products in this niche are Microsoft’s Active Server Pages,
Macromedia’s ColdFusion, and Sun’s Java Server Pages.
2. Ease of use
3. Html embeddedness
6. Stability
7. Speed
If you use this style, you can be positive that your tags will always be correctly
interpreted.
Unless you have a very, very strong reason to prefer one of the other styles, use
this one. Some or all of the other styles of PHP tag may be phased out in the
future—only this one is certain to be safe.
Short-open (SGML-style) tags
Short or short-open tags look like this: <?
//php script
?>
Short tags are, as one might expect, the shortest option. Those who escape into
and out of HTML frequently in each script will be attracted by the prospect of
fewer keystrokes; however, the price of shorter tags is pretty high. Additional
adjustment in the php.ini file is required to enable PHP to recognize the tags.
PHP code written with short-open tags is less portable because you can’t be
sure another machine will have enabled them in the php.ini file.
4.4 Syntax and variables and expressions
White space insensitive
White space includes spaces, tabs and carriage returns (new lines). PHP‗s
whitespace
In sensitivity does not mean that spaces and such never matter. (In fact, they
are crucial for
Separating the words in the PHP language.) Instead, it means that it almost
never matters how Many whitespace characters you have in a row—one
whitespace character is the same as many such characters.
Example: the following three codes have the same meaning
1. $four = 2 + 2; // single spaces
2. $four <tab>=<tab>2<tab>+<tab>2; // spaces and tabs
3. $four = 2+ 2;//multiple lines
Sometimes case sensitive
In PHP functions and basic program constructs like if, switch, else, for …in
case intensive whereas variables are. So, PHP is sometimes case sensitive and
sometimes not. Expressions
Expressions are combinations of tokens. The smallest building blocks of PHP
are the
Indivisible tokens, such as numbers (3.14159), strings (“two”), variables
($two), constants (TRUE), and the special words that make up the syntax of
PHP itself (if, else, and so forth). These are separated from each other by
whitespace and by other special characters such as parentheses and braces.
The next most complex building block in PHP is the expression, which is any
combination of tokens that has a value. A single number is an expression, as is
a single variable. Simple Expressions can also be combined to make more
complicated expressions in two ways.
✓ By putting an operator in between (for example, 2 + (2 + 2)), or
✓ By using them as input to a function call (for example, pow (2 * 3, 3 *
2)).
Operators that take two inputs go in between their inputs, whereas functions
take their inputs in Parentheses immediately after their names, with the inputs
(known as arguments) separated by commas. Braces make blocks
For example. In the if construct after the condition is matched if the number of
statements to execute are more than one you put them inside braces. if (3 == 2
+ 1)
print (“Good - I haven ‘t totally lost my mind. <BR>”); if (3 == 2 + 1)
{
print (“Good - I haven ‘t totally “);
print (“lost my mind. <BR>”);
}
Variables
The main way to store information in the middle of a PHP program is by using
a variable which is a way to name and hang on to any value that you want to
use later. Here are the most important things to know about variables in PHP.
✓ All variables in PHP are denoted with a leading dollar sign ($).
All variables in PHP start with a leading $ sign. After the initial $, variable
names must be composed of letters (uppercase or lowercase), digits (0–9), and
underscore characters (_). Furthermore, the first character after the $ may not
be a number.
✓ The value of a variable is the value of its most recent assignment.
✓ Variables are assigned with the = operator, with the variable on the left-
hand side and the expression to be evaluated on the right.
✓ Variables can, but do not need, to be declared before assignment.
✓ Variables have no intrinsic type other than the type of their current value.
In PHP, because types are associated with values rather than variables, no such
declaration is necessary—the first step in using a variable is to assign it a
value.
✓ Variables used before they are assigned have default values.
The following are valid variable declarations.
$pi=3.14;
$name=[kebede]
The following variable declarations are invalid in php.
Int x=3; / *no type declaration is necessary and the
variable
Example: the following program will add two numbers and display the result in
the page
<HTML>
<HEAD><title>some title</title>
</HEAD>
<BODY>
<?php
$first=6;
$second=5;
$result=$first+$second;
Echo $result;
?>
</BODY> </html>
Output with echo and print
The two most basic constructs for printing to output are echo and print. Their language
status is somewhat confusing, because they are basic constructs of the PHP language,
rather than Being functions. As a result, they can be used either with parentheses or
without them.
Echo
The simplest use of echo is to print a string as
argument. For example:
echo “This will print in the user’s browser window.”;
You can also give multiple arguments to the parenthesized version of echo, separated
by commas, as in:
echo “This will print in the “, “user’s browser window.”;
The parenthesized version, however, will not accept multiple arguments:
echo (“This will produce a “, “PARSE ERROR!”);
Print
The command print is very similar to echo, with two important
differences:
✦ unlike echo, print can accept only one argument.
✦ unlike echo, print returns a value, which represents whether the print
statement succeeded. The value returned by print will be 1 if the printing was
successful and 0 if unsuccessful.
4.5 Control statements and functions
Boolean expressions
Boolean expression is an expression with a result treated as either true or false.
1. Boolean constants
The simplest Boolean values are the constants TRUE and FALSE. We can use these
constants
Anywhere we would use a more complicated Boolean expression, and vice versa.
2. Logical operators
Logical operators combine other logical (aka Boolean) values to produce new Boolean
values. The standard logical operations (and, or, not, and exclusive-or) are supported
by php.
3. Comparison operators
Q. Read Boolean constants, logical and comparison operators with in its example?
Branching
Branching statements are used to select among a list of alternatives based on some
predefined condition. The two main structures for branching are if and switch.
1. If else
2. Switch
Looping
1. While loop
2. Do while loop
Q. Read and write php code by using branching, switch and looping?
User defined functions
Declaring functions
Function definitions have the following form:
function function-name ($argument-1, $argument-2, ..)
{
statement-1;
statement-2; …..
}
That is, function definitions have four parts:
The special word function
The name that you want to give your function
The function‗s parameter list—dollar-sign variables separated by
commas
The function body—a brace-enclosed set of statements
Example:
Function info($name,$age,$salary){
Echo “name:”.$name.”<br>“;
Echo “age:”.$age.”<br>“;
Echo “salary:”.$salary.”<br>“; }
Calling functions
Syntax: [Return_value=] Function_name(arguement1,
The return type is used when the function returns some value.
Example: to call the above function
info(“Abebe”,13,890);
Strings and regular expression functions
Strings are sequences of characters that can be treated as a unit— assigned to
variables, given as input to functions, returned from functions, or sent as output to
appear on your user‗s Webpage. The simplest way to specify a string in PHP code is
to enclose it in quotes, whether single quotes (‗) or double quotes (“).
Examples:
$x = „A literal string‟;
$y = “Another string”;
The difference between single quoting and double quoting is if you enclose a string in
single quotes, almost no interpretation will be performed; if you enclose it in double
quotes, PHP will splice in the values of any variables you include, as well as make
substitutions for certain special character sequences that begin with the backslash (\)
character.
Example:
$x = „everything I say‟;
$y = “Do you have to take $x so literally?\n<BR>“;
2. Post arguments
Q. Read in detail and give examples for Get and Post arguments of Passing
information b/n pages in PHP ?
4.7 PHP MySQL functions
1. Connecting to MySQL
The basic command to initiate a MySQL connection is
$link=mysql_connect($hostname,
$user, $password); if you‗re using variables, or $link=mysql_connect(„localhost‟,
„root‟, „sesame‟); if you‗re using literal strings. Here
$Hostname – the ip address or hostname of the MySQL server. If the MySQL server
and the php server are on the same machine use localhost or 127.0.0.1, else use the ip
address of the database server.
$User – the user name of the database if specified by one of the grant commands. If
username and password is not given to the database (which is not recommended) use
root as your username which is the default.
$Password – the password of the database if specified by one of the grant commands.
The default password for any MySQL database is empty, so if password is not granted
leave it null. $link – is a variable and is called the link identifier. You will use this
variable later.
2. Selecting the database
After creating the connection identifier the next thing you will do is select a database
among the databases you have created. To do this you will use the mysql_select_db()
method. Syntax:
$db=mysql_select_db(„dbname‟,[link identifier]);
Here: Dbname – the name of the database you are operating on.
Link identifier – is an optional link identifier variable you have created earlier in the
mysql_connect function. Use this if there are more than one link identifiers in your
page.
3. Making MySQL queries
A database query from PHP is basically a MySQL command wrapped up in a tiny PHP
function called mysql_query(). This is where you use the basic SQL workhorses of
SELECT, INSERT, UPDATE, and DELETE, CREATE or DROP a table (but not
those to create or drop an entire database) can be used with this PHP function.
Syntax: [$resultvar=] mysql_query(“query”,[link identifier]);
$resultvar – is an optional result variable. This is used when the query is a select
statement. Query – is any valid insert, delete, update, select, create table or drop
table statement enclosed by quotes. It is a good habit to hold the query in a separate
variable to add flexibility to your code.
Link identifier-is an optional link identifier
Example:
$query=“select * from student”;
$result=mysql_query($query);
While($row=mysql_fetch_array($result)){
Echo “$row[„id‟] . $row-[„name‟] . $row[„department‟]”;
//mysql_fetch_array() could be used with the enumerated type
just
//like the mysql_fetch_row function. }
5. Closing the connection
After you have finished the mysql query the last thing you have to do is close the
connection.
Syntax: MySQL-close([link identifier]);
Q. Read the following php concepts such as string and regular expressions in the
reference book?
5.1 Sessions
A PHP session variable is used to store information about, or change settings for a user
session. Session variables hold information about one single user, and are available to all
pages in one application. A PHP session allows you to store user information on the server for
later use (i.e. username, shopping items, etc.). However, session information is temporary and
will be deleted after the user has left the website. If you need a permanent storage you may
want to store the data in a database.
Starting a PHP Session
Before you can store user information in your PHP session, you must first start up the
session.
<?php session_start(); ?> <html>
<body>…..
</body>
</html>
The code above will register the user's session with the
server,
allow you to start saving user information, and assign a UID for that user's session.
Storing a Session Variable
The correct way to store and retrieve session variables is to use the PHP $_SESSION
variable:
<?php
session_start(); //
store session data
$_SESSION['views']=1;
?>
<html>
<body>
<?php
//retrieve session data
echo "Pageviews=". $_SESSION['views'];
?>
</body>
</html>
Q. Read in detail how can create and destroy session in PHP ?
Example
In the example below, we will create a cookie named "user" and assign the
value "Alex Porter" to it. We also specify that the cookie should expire
after one hour:
<?php
setcookie("user", "Alex Porter", time()+3600);
?>
<html>
<body>
</body>
</html>
Note: The value of the cookie is automatically URLencoded when sending the cookie,
and automatically decoded when received (to prevent URLencoding, use
setrawcookie() instead).
How to Retrieve a Cookie Value?
The PHP $_COOKIE variable is used to retrieve a cookie value.
Delete example:
<?php
?>
This chapter deals with the Opening file, Managing file upload and download and PHP directory.
To deliver these contents active learning methods such as brain storming, interactive lecture, group
discussion and independent learning will be used and assess students‘ achievement, continuous
assessments such as quiz, test, class activities, assignments and others will be used.
The first parameter of this function contains the name of the file to be opened and the
second parameter specifies in which mode the file should be opened:
Example
<html>
<body>
<?php
$file=fopen("welcome.txt","r");
?>
</body>
</html>
Modes Description
a Append. Opens and writes to the end of the file or creates a new
file if it doesn't exist
Example
The following example generates a message if the fopen() function is unable to open
the specified file:
<html>
<body>
<?php
$file=fopen("welcome.txt","r") or exit("Unable to open file!");
?>
</body>
</html>
Q. Write code in order to check end of file, to read file line by line and to read
character by character and to close file?
Why MySQL?
Fast ,reliable ,easy to use , robust and powerful and scalable
Cost - MySQL is Open Source Software.
The subset of SQL that enables you to insert data and to update and delete existing
records in a table is known as the Data Manipulation Language.
The INSERT statement adds a new row of data to a table. At its simplest, INSERT is
followed by a table name, the keyword VALUES, and a list of values in parentheses that
correspond to each column in the table in turn.
The DELETE Statement
The DELETE statement is used to remove data rows from a table. Its syntax is similar to
a SELECT statement: You supply a table name after the keyword FROM and use a
WHERE clause to filter the rows that are to be deleted.
To delete only a single row from a table, you should ensure that the WHERE clause will
match only that row. Usually, you should check the value of the table's PRIMARY KEY
command. The data in your file must be in a structured format the default format is
one record on each line, with values separated by tabs.