0% found this document useful (0 votes)
2 views

p 7. Web Programming Module

The document is a course handout for Web Programming at Bonga University, covering topics such as the Internet's history, the World Wide Web, client-server architecture, and HTML. It includes detailed explanations of web page design, development, and the structure and syntax of HTML. Active learning methods and continuous assessments are emphasized throughout the course to enhance student engagement and understanding.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

p 7. Web Programming Module

The document is a course handout for Web Programming at Bonga University, covering topics such as the Internet's history, the World Wide Web, client-server architecture, and HTML. It includes detailed explanations of web page design, development, and the structure and syntax of HTML. Active learning methods and continuous assessments are emphasized throughout the course to enhance student engagement and understanding.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 59

BONGA UNIVERSITY

College of Engineering and Technology


Department of computer Science
Course Handout: Web Programming

(Code: CoSc 3081)

Prepared by: Amsalu T.

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.

1.1 Overview of Internet

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.

1.2 World Wide Web:

What is the World Wide Web?


• The World Wide Web (WWW) is most often called the Web.

• The Web is a network of computers all over the world.

• All the computers in the Web can communicate with each other.

• All the computers use a communication standard called HTTP.

How does the WWW work?


• Web information is stored in documents called Web pages.

• Web pages are files stored on computers called Web servers.


• Computers reading the Web pages are called Web clients.

• 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.

1.3 Client-server Architecture:

How does the browser fetch the pages?


HTTP is a communication standard governing the requests and responses that take
place between the browser running on the end user‘s computer and the web server. The
server‘s job is to accept a request from the client and attempt to reply to it in a
meaningful way, usually by serving up a requested web page—that‘s why the term
server is used. The natural counterpart to a server is a client, so that term is applied
both to the web browser and the computer on which it‘s running.
Between the client and the server there can be several other devices, such as
routers, proxies, gateways, and so on. They serve different roles in ensuring that the
requests and responses are correctly transferred between the client and server.
Typically, they use the Internet to send this information.

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.

The Request/Response Procedure

1. You enter http://server.com into your browser‘s address bar.

2. Your browser looks up the IP address for server.com.

3. Your browser issues a request for the home page at server.com.

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.

7. Your browser displays the web page.

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

• Gather the requirements


• Organize the information
• Structure the web site

✓ Hierarchical Structure

✓ Hypertext Structure

✓ Database Structure

 Develop a Navigation Scheme

 Built-in browser navigation

 Reflect the Structure in the navigation

 Make it Flexible

 Reflect information organization

 Consistent wording

 Use of Navigation Bars

 Use of Text, Icons and Buttons

 Drop-down lists
 Layout the Web Pages

 Limitations of your HTML Editor

 Browser Display

 Monitor Resolution

 Data Transfer – file size

 Page Elements for Layout

 Using HTML Tables


 Web Accessibility
 Test

 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:

 What is the goal and purpose of the site

 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.

2.2 Information Architecture & visualization; static & dynamic pages,

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

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 describes the structure of Web pages using markup


• HTML elements are the building blocks of HTML pages
• HTML elements are represented by tags
• HTML tags label pieces of content such as "heading", "paragraph", "table", and
so on

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

<tag_name attr1="val1” attr2="val2” …>…</tag_name>


E.g. <font face= “arial” size= "9”>Hello</font>

❖ Not case sensitive.


Q. Explain in detail about html, structure and syntax of html?

2.3.1 HTML Tags


html -Everything in the document should be within <html> &</html>
head -Contains information which is not displayed in the browser display area and
may contain other tags in it : Format: <head>…</head>
title -Sets the title of the web page to be displayed in the browser‘s title bar and is
found within the <head> tag. :Format: <title>…</title>
body -The body tag contains the visible part of the web page and is displayed in the
display area of the browser. It contains several other tags and content in it. Format:
<body>…</body>
Headings -Headings are predefined formats for text presentation and they are six
heading formats defined in HTML:
<h1> up to <h6>
<h1> the largest font size
<h6> the smallest font size
Format :<h1>…</h1>
E.g. <h2>a text in heading two</h2>

Paragraph (<P>): The <p> element defines a paragraph


E.g. <p >here is the content of paragraph</p>

Bold - makes the text enclosed appear in bold.


Format: <b>…</b> or <strong>…</strong>E.g. <b>a text in bold</b>

Italics - makes a text appear in italics


Format: <i>…</i> or <em>…</em>. E.g. <i>a text in italics</i>
underline - Makes a text appear underlined.
Format: <u>…</u> E.g. <u>underlined text</u>
• <strong>: like <b> makes the text enclosed appear in bold
• <i>: makes the text enclosed appear in Italic text
• <em>: like <i> makes the text enclosed appear in Italic text
• <mark>: makes the text enclosed appear in Marked (highlight color) text
• <small>: makes the text enclosed appear in very small text
• <del> : makes the text enclosed appear in deleted text
• <ins>: makes the text enclosed appear in inserted text
• <sub> : makes the text enclosed appear in subscript text
• <sup>: makes the text enclosed appear in superscript text

Q. Write simple html code by using the html tags?

3.3.2 Paragraph: definition of paragraph

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

Format: <img> {no end tag}


▪ Supported image formats are: gif, jpg/jpeg, png
▪ The filename of the image source is specified in the src attribute
▪ The src attribute specifies the URL (web address) of the image
▪ The source file (src), alternative text (alt), width, and height are provided as
attributes:
E.g. <img src= “image1.gif” alt= “Site Logo”>

Width and height Attributes


Images in HTML have a set of size attributes, which specifies the width and height of
the image:
<img src="capture1.jpg" width="500" height="600">

Images in another Folder

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:

<img src="/images/capture1.jpg" style="width: 128px; height: 128px ;">

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?

2.3.6 Tables - insert tabular data and design page layout.


Tags involved: <table>, <tr>, <td>, <th>, <caption>
Format: <table>
<caption> table caption</caption>
<tr>
<td>…</td> <td>…</td> …
</tr>
<tr>
<td>…</td> <td>…</td> …
</tr> …...
</table>
E.g. <table>
<caption align= “center” valign= “bottom”>table 1.0</caption>
<tr>
<th>Column 1</th> <th>Column 2</th>
</tr>
<tr>
<td>Cell 1</td> <td>Cell2</td>
</tr>
<tr>
<td>Cell 3</td> <td>Cell 4</td>
</tr>
</table>
Example you can observe the following Examples:
<html> <body bgcolor="magenta">
<h2 align=center> Here is a simple HTML Table</h2>
<table border=1 width="90%" align="center">
<tr> <th> <font color="YELLOW" size= "50">FULL NAME </font></th>
<th> <font color="BLUE" size= "50"> Age</font></th>
<th> <font color="Green" size= "50"> Gender</font></th>
<th style="color:cyan; font-size:50px;">ID Number</TH>
</tr>
<tr>
<td style="color:yellow; font-size:20px;"> Abebe Alem</td>
<td style="color:yellow; font-size:20px;"> 23</td>
<td style="color:yellow; font-size:20px;"> MALE</td>
<td style="color:yellow; font-size:20px;"> 11111</td>
</tr>
<tr>
<td style="color:yellow; font-size:20px;"> Elsa Tesfahun</td>
<td style="color:yellow; font-size:20px;"> 24</td>
<td style="color:yellow; font-size:20px;"> Female</td>
<td style="color:yellow; font-size:20px;"> 22222</td>
</tr>
<tr>
<td style="color:yellow; font-size:20px;"> Abrham Bewuket</td>
<td style="color:yellow; font-size:20px;"> 25</td>
<td style="color:yellow; font-size:20px;"> MALE</td>
<td style="color:yellow; font-size:20px;"> 33333</td>
</tr>
<tr>
<td style="color:yellow; font-size:20px;"> Meron Fentahun</td>
<td style="color:yellow; font-size:20px;"> 26</td>
<td style="color:yellow; font-size:20px;"> Female</td>
<td style="color:yellow; font-size:20px;"> 444444</td>
</tr>
<tr>
<td style="color:yellow; font-size:20px;"> Mekuanent Abebe</td>
<td style="color:yellow; font-size:20px;"> 27</td>
<td style="color:yellow; font-size:20px;"> MALE</td>
<td style="color:yellow; font-size:20px;"> 555555</td>
</tr>
<tr>
<td style="color:yellow; font-size:20px;"> Hasset Muluken</td>
<td style="color:yellow; font-size:20px;"> 29</td>
<td style="color:yellow; font-size:20px;"> Female</td>
<td style="color:yellow; font-size:20px;"> 666666</td>
</tr> </body> </html>

Output

Q. Read in detail table attributes, row attributes and data/heading attributes?


HTML comments are used to insert commented text in an html document
You can add comments to your HTML source by using the following syntax
Format: <! -- comment text -->
Notice that there is an exclamation point (!) in the opening tag, but not in the closing
tag.
Note: Comments are not displayed by the browser, but they can help document your
HTML source code.

E.g. <!-- this is a comment text -->


Special characters (named characters) – these are characters
i. Not found on the standard keyboard. e.g. ©,€,®,™
ii. Used by HTML e.g. <
iii. Ignored by browsers e.g. blank spaces
Format: &code;
Examples: &copy; © &lt; = < &amp; = & &nbsp; = space
Other Special characters and symbols supported by HTML
Char Number Entity Description
© &#169; &copy; Copyright Sign
® &#174; &reg; Registered Sign
€ &#8364; &euro; Euro Sign
™ &#8482; &trade; Trademark

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.

2.3.7 HTML Forms


HTML Forms – are used to gather input from users
• The HTML <form> element defines a form that is used to collect user input.
• Form elements are different types of input elements, like text fields, checkboxes,
radio buttons, submit buttons, and more.
Format: <form>
--- Form elements-----
</form>
The <input> Element
The <input> element is the most important form element.

Type Description

<input type="text"> Defines a one-line text input field

<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)

<input type="submit"> Defines a submit button (for submitting the form)

The <input> element can be displayed in several ways, depending on


the type attribute.

The input is usually sent to a server-side script for processing

The form data can be sent in two methods: GET & POST

When to Use GET?

The default method when submitting form data is GET.


However, when GET is used, the submitted form data will be visible in the page
address field:
When to Use POST?
Always use POST if the form data contains sensitive or personal information.
The POST method does not display the submitted form data in the page address field.

➢ 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

✓ For large & secure data


✓ Input is sent as a data stream after the request URL
✓ POST has no size limitations, and can be used to send large amounts of data.
✓ Form submissions with POST cannot be bookmarked

Tags: The <form> tag

➢ Contains all input elements in the form


➢ Defines the method of sending data
➢ Defines the server-side script responsible for accepting the Ex.
<select name=“department”>
<option value=“1”>Computer Science</option>
<option value=“2”>Information Science</option>
<option value=“3”>Computer Engineering</option>
</select>
For more Clearly show the following simple Bonga University
CS students Registration Form
Q. Read in detail the input attributes of form such as list box, text area, check box,
radio box, button(reset and submit), hidden field, password field, file input, image
input and combo box (select) it‘s advantages, format and give example for each ?
2.3.8 Frames

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.

A collection of frames in the browser window is known as a frameset.

To create a frameset document,

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.

Each frame is then represented by a <frame> element.

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:

When your navigation bar is rather large in size (such as thumbnails of


photographs in a gallery).By using frames, the user does not need to reload the
navigation bar each time she views a new page.
When you’re main document is very long and the navigation bar provides shortcuts
to parts of the main document.

Q. Read and practice different HTML code by using html tags?

Chapter 3

Cascading Style Sheets (CSS)

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?

3 Ways of style sheet

Q. Where to put style sheets in an html document?

There are three ways to insert style sheets in a document.

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.

➢ Multiple and Descendant Selectors

➢ Rule Conflicts, Priority, and Precedence

➢ Value Inheritance

➢ percent

➢ Pitch and the Value of a Pixel

➢ Font-size Keywords

➢ Color Units

➢ The Difference Between <div> and <span>

➢ Style Inheritance

➢ Style Rules Precedence

➢ Style Sheet Layers

➢ 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.

4.1 Overview of Script

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:

JavaScript and VBScript are the dominant ones. JavaScript is


➢ A client-side scripting language.
➢ Supported by all the major web browsers.
➢ Totally different from java programming language.
JavaScript gives the developer a means to
➢ Validate user input.
➢ Put dynamic text in an HTML page.
➢ Reacts to events (interactive).
Syntax: Case sensitive unlike HTML.
Ignores tabs, whitespaces and newlines that appear between tokens in a program.
Semicolon (;) at the end of a statement is optional if each statement is on a separate
line. If more than one statement on a line separates them using semicolon.
Identifiers

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

i, distance_value, v13_dummy, $str and some_variable

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.

4.2 Conditional statements


1. If…. Else

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]

Calling: [var_name =] function_name(arg_list)

4.3. How to add JavaScript to an HTML page

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

JavaScript is an Object-Oriented Programming (OOP) language. An OOP language


allows you to define your own objects and make your own variable types. An object is
just a special kind of data. An object has properties and methods. Properties

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?

4.4 JavaScript event handlers


Events
By using JavaScript, we have the ability to create dynamic web pages. Events are
actions that can be detected by JavaScript.

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.

Examples of events: A mouse click


➢ A web page or an image loading
➢ Mousing over a hot spot on the web page
➢ Selecting an input field in an HTML form
➢ Submitting an HTML form
➢ A keystroke

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

Server-Side Scripting with PHP


Chapter Description

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.

5.1 Overview of PHP

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.

5.2 Reasons to love PHP


1. Cost

2. Ease of use
3. Html embeddedness

4. Cross platform compatibility

5. Not tag based

6. Stability

7. Speed

Q. Read and discus above reasons of to love php?

5.3 Adding PHP to HTML


Anything compatible with HTML on the client side is also compatible with
PHP. PHP could not care less about chunks of JavaScript, calls to music and
animation, applets, or anything else on the client side. PHP will simply ignore
those parts, and the Web server will happily pass them on to the client.
Escaping from HTML
The process of telling the program when to spring into action by using special
PHP tags at the Beginning and end of each PHP section is called escaping from
HTML or escaping into PHP.
There are four styles of PHP tags and different rationales for using them. Part
of the decision,
However, is simply individual preference: what the individual programmer is
comfortable or what a team has decided upon for reasons of their own.
Canonical PHP tags
The most universally effective PHP tag style is:
<?php
//php script
?>

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

Should start with the dollar sign. */


Char $v= “c”; // no type declaration.

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.”;

Or equivalently: 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>“;

$z = „Do you have to take $x so literally?\n<BR>‟;


Now let‗s display the values of the two variables:
echo $y;
echo $z;

You should expect to see the browser output:


Do you have to take everything I say so literally?
Do you have to take $statement so literally?\n
4.6 Passing information between pages
In webpage design passing information is very important either to transfer data from
one page to another for further processing or for insertion to a database. HTML forms
are mostly useful for passing a few values from a given page to one single other page
of a Web site.
There are two ways to transfer data from one page to another.
1. Get arguments

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

4. Fetching data sets


The result of a query returned by the mysql_query() function is an interger showing
the success or failure of the function not the desired data. So you have to use one of
the mysql_fetch_..() functions to get the actual result. There are many functions to do
so, but the most commonly used ones are- Mysql_fetch_row($result) – this function
takes the result of the mysql_query() function as an argument and returns the data as
an enumerated array. Example: assume the student table has three attrubutes -
id,name and department.
$query=“select * from student”;
$result=mysql_query($query);
While($row=mysql_fetch_row($result)){
Echo “$row[0].$row[1].$row[2]”;//counting starts from 0
not 1 }
Mysql_fetch_object($result) - this function takes the result of the mysql_query()
function as an argument and returns the data as an object. Example:
$query=“select * from student”;
$result=mysql_query($query);
While($row=mysql_fetch_object($result)){
Echo “$row->id . $row->name . $row->department”;
}
Mysql_fetch_array($result) - this function takes the result of the mysql_query()
function as an argument and returns the data as an enumerated or associative array.
This is the most widely used fetching function since results are displayed in
association to their column values.

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?

 String operators and functions


 Inspecting strings
 Finding characters and
substrings
 Comparison and searching
Q. Read the above php concepts in the reference book or from Internet?

4.8 Form validation


Form validation is the process of making sure the data inserted in html forms by the
user is valid or invalid. Validation could be of
1. Type – checking the type of the data inserted. There are methods to check .
 Ctype_alpha(string $text) - Checks if all of the characters in the provided string,
text , are alphabetic.
 Ctype_alnum(string $text) - Checks if all of the characters in the provided string,
text , are alphanumeric. In the standard C locale letters are just [A-Za-z].
 Ctype_digit(string $text) - Checks if all of the characters in the provided string,
text, are numerical.
 Ctype_lower(string $text) - Checks if all of the characters in the provided
string,text, are lowercase letters.
2. Length – validate the length of strings inserted in forms.
 Strlen(string $text) – this function takes a string as an argument and returns the
length of that string.
Example: if there is a rule that says usernames should be at least 8 characters, you
can check it using the strlen() method.
3. Pattern of characters in the string – use regular expressions to check
patterns.  Ereg() //read and Eregi() //read
4. Against database constraints – this validates user inputs against database
constraints. Example:
 Against null values ,against foreign key constraints, unique and Primary key
To validate entey values against database constraints
 First accept the values and write a the appropriate query to check those entered
values against the database values
 If they fail return an error message and Else continue
Q. Write the successful registration form for students by using php and connect with
your database?in a program that registers students, assume you have the following
rules for username.
1. The username of the student is unique in the table,
2. It should be at least five and at most ten characters long,
3. It should contain only alphabetic characters. so to validate the
user
name of a new student.

Chapter 5: Sessions and Cookies management in PHP


Chapter Description
This chapter deals with the Session, cookies, and how to create, store, destroy and close
session and cookies. 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.

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 ?

5.2 What is a Cookie?


A cookie is often used to identify a user. A cookie is a small file that
the server embeds on the user's computer. Each time the same computer
requests a page with a browser, it will send the cookie too. With PHP, you
can both create and retrieve cookie values.
How to Create a Cookie?
The setcookie() function is used to set a cookie.
Note: The setcookie() function must appear BEFORE the <html> tag.
Syntax

setcookie(name, value, expire, path, domain);

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.

How to Delete a Cookie?


When deleting a cookie you should assure that the expiration date is in the past.

Delete example:

<?php

// set the expiration date to one hour ago


setcookie("user", "", time()-3600);

?>

Q. Read in detail to create and destroy cookies in PHP?


Chapter 6: Files and Directories in PHP
Chapter description

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.

6.1 Opening a File


The fopen() function is used to open files in PHP.

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>

The file may be opened in one of the following modes:

Modes Description

r Read only. Starts at the beginning of the file

r+ Read/Write. Starts at the beginning of the file


w Write only. Opens and clears the contents of file; or creates a
new file if it doesn't exist

w+ Read/Write. Opens and clears the contents of file; or creates a


new file if it doesn't exist

a Append. Opens and writes to the end of the file or creates a new
file if it doesn't exist

Read/Append. Preserves file content by writing to the end of the


a+
file

x Write only. Creates a new file. Returns FALSE and an error if


file already exists

x+ Read/Write. Creates a new file. Returns FALSE and an error if


file already exists
Note: If the fopen() function is unable to open the specified file, it returns 0 (false).

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?

6.2 Managing File uploads and download


A very useful aspect of PHP is its ability to manage file uploads to your server. Allowing users
to upload a file to your server opens a whole can of worms, so please be careful when enabling
file uploads.
Uploading file has two parts – the client side and the server side.
The client side looks like the following
<form enctype="multipart/form-data" action="uploader.php"
method="POST">
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>
Here is a brief description of the important parts of the above code:
enctype="multipart/form-data" - Necessary for our to-be-created PHP file to function properly.
action="uploader.php" - The name of our PHP page that will be created, shortly.
method="POST" - Informs the browser that we want to send information to the server using
POST.
input name="uploadedfile" - uploadedfile is how we will access the file in our PHP script.
Q. Write the code to upload and download file by using php ?
6.3 PHP Directory Introduction
The directory functions allow you to retrieve information about directories and their
contents.
PHP Directory Functions
PHP: indicates the earliest version of PHP that supports the function.
Function Description PHP
chdir() Changes the current directory 3
chroot() Changes the root directory of the current process 4
dir() Opens a directory handle and returns an object 3
closedir() Closes a directory handle 3
getcwd() Returns the current directory 4
opendir() Opens a directory handle 3
readdir() Returns an entry from a directory handle 3
rewinddir() Resets a directory handle 3
scandir() Lists files and directories inside a specified path 5
Example
<?php
//Get current directory
echo getcwd(); echo
"<br />";
//Change to the images directory
chdir("images"); echo "<br />";
echo getcwd(); ?>

Q. Practice the above php function in the w3 school data from


table?
Chapter 7: Data Base Manipulation Using PHP
Chapter description
This chapter deals with the Overview of database, Operations of database and table,
Locking and Concurrency, load data from file, Web security and cryptography theory.
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.

7.1 Overview of database


A database is a collection of related data. By data, we mean known facts that can be
recorded and that have implicit meaning.
Q. Explain the DBMS and the advantages of DBMS?

Why MySQL?
 Fast ,reliable ,easy to use , robust and powerful and scalable
 Cost - MySQL is Open Source Software.

7.2 Operations of database and table Creating


databases
You use the CREATE DATABASE command to create a new database. To create a
new database named newdb, issue the following command.
The database name must be unique. If you attempt to issue a CREATE
DATABASE statement for a database that already exists, you will see an error.
Altering database
The ALTER DATABASE statement enables you to change the characteristics of an
existing database.
Dropping database
Use the DROP DATABASE command to drop a database completely. Use this
command with extreme caution you cannot recover a dropped database unless you
have a backup.
Q. Read and write the code the following functions of table and
database?

1. Creating a New database and Table


2. Storage Engines
3. Altering database and Tables
4. Dropping database and Tables
Working with Data

The INSERT Statement

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

column to ensure that an exact match is found.


The UPDATE Statement
The UPDATE statement is used to change one or some of the values in a data row. As
with DELETE, you include a WHERE clause to indicate that this row or rows are to be
updated. Without a WHERE clause, UPDATE performs the same update on every row the
table. Unless this is the result you want, always include a WHERE clause in an UPDATE
statement.

The REPLACE Statement


The REPLACE statement works just like INSERT, except that if a row already exists in
the table with the same PRIMARY KEY value as the new data, the new row replaces it.

Therefore, REPLACE never causes a PRIMARY KEY violation.

Loading Data from a File


You can load data from an external file into MySQL using the LOAD DATA INFILE

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.

 Q. Read in the following of database contents in reference book or in w3 school data?


 Insert statement
 Delete statement
 Update statement
 Replace statement
 load data from file
 Locking and concurrency
 General optimization tips
 Web security and cryptography theory

You might also like