ITT 05103 - 2023mimi Internet Programming-1
ITT 05103 - 2023mimi Internet Programming-1
ITT 05103 - 2023mimi Internet Programming-1
PROGRAMMING
NTA LEVE 5 SEMESTER I
Assessment
1. Course Work – 50%
i. Test 1 – 15%
ii. Test 2 – 15%
iii. Individual assignment – 10%
iv. 2 Group assignments – 10%
• JavaScript
Websites
• CSS are style sheets that specify the formatting of a Web page
for both static and dynamic Web pages.
• HTML 5
• HTML is a standard tagging language for developing web
pages. Each webpage contain HTML code to define and display
the contents of the page.
• PHP
• PHP is a server side programing language that is used to
create dynamic contents and adds user interaction to the
website by connecting to the database and webserver.
Technologies for Internet programming
Web Technologies: Internet programming relies on various technologies and languages, including
but not limited to:
• HTML (Hypertext Markup Language): Used for structuring and presenting content on web pages.
• CSS (Cascading Style Sheets): Used for styling and formatting web page elements.
• JavaScript: A scripting language used for adding interactivity and dynamic behavior to web pages.
• Server-Side Scripting Languages: Such as PHP, Python, Ruby, Node.js, and others, used to
process requests and generate dynamic content on the server.
• Databases: Used for storing and retrieving data, commonly through database management
systems like MySQL, PostgreSQL, MongoDB, and more.
• Web Frameworks: Frameworks like Ruby on Rails, Django, Express.js, and others provide pre-
built tools and structures to streamline web development.
The evolution of HTML
What is the HTML code for web page?
• This resulted in the evolution of the Web, also referred as World Wide Web or
WWW.
• The Web is a way to access information using the Internet that is referred to as
a network of networks.
• A Web page is a file that contains information and instructions to display the
information to the users.
Web Communication
• Web pages are stored on a Web server to make them available on the Internet so
that users can view them.
• A Web server is a computer with high processing speed connected to the Internet
and is used to host Web pages.
• The most popular protocol used to view Web pages is Hypertext Transfer
Protocol (HTTP).
• It is a protocol that specifies how a Web page will be retrieved from the Web
Server.
Static Web Pages
• A static Web page consists of contents specified by the Web page
designer.
• The same content is displayed to each user on the Internet each time the
page is requested.
• Therefore, such a Web page is called a static Web page, as the contents of
the Web page remain unchanged.
• The only way to update a static Web page is to change the content
manually.
Static Web Pages PROS AND
CONS
• ADVANTAGES
• Ideal for specifying the content appearance as static Web pages focus on
content presentation, which is one-way flow of information.
• DISADVANTAGES
JavaScript
<html>
<head>
<title>
• ………………..
• …………….....
</title>
</head>
<body>
.....................................
……..............................
</body>
</html>
BASIC HTML TAGS
• The <!DOCTYPE html> declaration defines this document to
be HTML5
• The first tag in a pair is the start tag, 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
Tip: The start tag is also called the opening tag, and the end tag the closing
tag.
BASIC HTML5 STRUCTURE
<!DOCTYPE html>
<html>
<head>
<title>
• ………………..
• …………….....
</title>
</head>
<body>
.....................................
……..............................
</body>
</html>
BASIC HTML TAGS
• The <!DOCTYPE html> declaration defines this document to
be HTML5
• The first tag in a pair is the start tag, 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
Tip: The start tag is also called the opening tag, and the end tag the closing
tag.
HTML Editors
• Write HTML Using Notepad or TextEdit
• <h1> defines the most important heading. <h6> defines the least
important heading:
• Example
• <h1>This is heading 1</h1>
• <h2>This is heading 2</h2>
• <h3>This is heading 3</h3>
• An element organizes the content in a Web page
hierarchically, which forms the basic HTML structure.
Elements
• It consists of
• tags,
• attributes,
• and content.
• dir – Specifies the direction of the text present for the content.
<!DOCTYPE html>
• <!DOCTYPE html> <html>
<body>
• <html>
<h1>This is heading 1</h1>
• <body> <h2>This is heading 2</h2>
<h3>This is heading 3</h3>
• <h1>My First Heading</h1> <h4>This is heading 4</h4>
<h5>This is heading 5</h5>
<h6>This is heading 6</h6>
• </body>
• </html>
Html basic elements
• HTML Paragraphs
•
• HTML paragraphs are defined with the <p> tag: <!DOCTYPE html>
• <html>
• <body>
• Example
• <p>This is a paragraph.</p>
• <p>This is a paragraph.</p> • <p>This is another paragraph.</
• </html>
HTML Links
• HTML Links
• Example
• The most important attribute of the <a> element is the href attribute,
which indicates the link's destination
• <html>
• <body>
• <h2>HTML Links</h2>
• </body>
• </html>
HTML Links - The target
Attribute
By default, the linked page will be displayed in the current browser window. To
change this, you must specify another target for the link.
_self - Default. Opens the document in the same window/tab as it was clicked
PAGE 34
Links - The target Attribute
using “blank”
Example
PAGE 35
Absolute URLs vs. Relative URLs
PAGE 36
Examples
• <h2>Absolute URLs</h2>
• <p><a href="https://www.google.com/">Google</a></p>
• <h2>Relative URLs</h2>
PAGE 37
Html basic elements
• HTML Images
• The source file (src), alternative text (alt), width, and height are
provided as attributes:
• Example
<a href="mailto:someone@example.com">Send
email</a>
PAGE 39
Link Titles
• The title attribute specifies extra information about an
element. The information is most often shown as a
tooltip text when the mouse moves over the element.
Example
PAGE 40
Link-Summary
• Use the mailto: scheme inside the href attribute to create a link
that opens the user's email program
PAGE 41
Html basic elements
• HTML Buttons
• Example
• <button>Click me</button>
Button
• <!DOCTYPE html>
• <html>
• <body>
• </body>
• </html>
HTML BASIC ELEMENTS
HTML Lists
HTML lists are defined with the <ul> (unordered/bullet list) or the
<ol> (ordered/numbered list) tag, followed by <li> tags (list items):
• Example
• <ul>
• <li>Coffee</li>
• <li>Tea</li>
• <li>Milk</li>
• </ul>
HTML lists allow web developers to group a
set of related items in lists.
An unordered HTML list:
• Item
• Item
• Item
• Item
1. First item
2. Second item
3. Third item
4. Fourth item
PAGE 45
HTML Description Lists
• The <dl> tag defines the description list, the <dt> tag defines the term (name),
and the <dd> tag describes each term:
• <dl>
<dt>Coffee</dt>
<dd>- black hot drink</dd>
<dt>Milk</dt>
<dd>- white cold drink</dd>
</dl>
PAGE 46
HTML BASIC ELEMENTS
• <br> is an empty element without a closing tag (the <br> tag defines a
line break).
• Empty elements can be "closed" in the opening tag like this: <br />.
• HTML5 does not require empty elements to be closed. But if you want
stricter validation, or if you need to make your document readable by
XML parsers, you must close all HTML elements properly.
BASIC HTML ELEMENTS
• HTML Comment Tags
• You can add comments to your HTML source by using the following
syntax:
• Example
• <p>This is a paragraph.</p>
PAGE 50
Example
<table style="width:100%">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr> Firstname Lastname Age
<tr> Jill Smith 50
<td>Jill</td> Eve Jackson 94
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
</table>
HTML Table - Add a Border
PAGE 52
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
}
</style>
</head>
<body>
<table style="width:100%">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
<td>80</td>
</tr>
</table>
</body>
</html>
PAGE 53
ATTRIBUTES
• HTML Attributes
• <body style="background-color:powderblue;">
Example
• <h1 style="background-color:#ff6347;">...</h1>
• CSS saves a lot of work. It can control the layout of multiple web pages all at
once.
The most common way to add CSS, is to keep the styles in separate CSS files.
Style attribute
Use the style attribute for styling HTML elements
Example
• <h1 style="background-color:#ff6347;">...</h1>
• Less HTML Code: CSS helps in reducing the file size of HTML
documents by specifying the formatting instructions in another file.
CSS Syntax • For example, the values of the color property include red,
green, yellow, and so on.
• The property and the value for a selector are separated with a
colon (:).
• They are enclosed within the curly brackets ({}) that is known
property
as the declaration block. value
• Example: curly braces enclosure
Selector (for this case paragraph
: Separate property and value
P{ ; terminator
font-size:12px;
color:red;
}
• Selectors refer to the HTML elements with the styles the
users want to apply to them.
Selector Description
Type selector Applies to HTML Tags e.g. H1,BODY,P, etc.
Class selector .classname {
Selectors }
color:green;
<p class=“classname”>
ID selector #idname{
color:green;
}
<p id=“idname”>
Universal *{
selector color:green;
}
Inline CSS
• An inline CSS is used to apply a unique style to a single HTML
element.
• This example sets the text color of the <h1> element to blue:
• Example
• An internal CSS is defined in the <head> section of an HTML page, within a <style> element:
Example
• <!DOCTYPE html>
• <html>
• <head>
• <style>
• body {background-color: powderblue;}
• h1 {color: blue;}
• p {color: red;}
• </style>
• <head>
External CSS
• An external style sheet is used to define the style for many HTML pages.
• With an external style sheet, you can change the look of an entire web site, by changing one
file!
• To use an external style sheet, add a link to it in the <head> section of the HTML page:
Example
• <!DOCTYPE html>
• <html>
• <head>
• </head>
Example
• <!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="mystyle.css">
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
"mystyle.css"
• body {
background-color: lightblue;
}
h1 {
color: navy;
margin-left: 20px;
}
External styles are defined within the <link> element,
inside the <head> section of an HTML page:
Example
• <!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="mystyle.css">
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
CSS-external example
• An external style sheet can be written in any text editor, and must be saved with a .css extension.
• The external .css file should not contain any HTML tags.
• Here is how the "mystyle.css" file looks :
• body {
• background-color: lightblue;
• }
• h1 {
• color: red;
• margin-left: 20px;
• }
• p{
• color: blue;
• margin-left: 20px;
• }
The id Attribute
• To define a specific style for one special element, add an id
attribute to the element:
• then define a style for the element with the specific id:
Example
• #p01 {
• color: blue;
The class Attribute
• then define a style for the elements with the specific class:
Example
• p.error {
• color: red;
• }
HTML Forms
HTML Forms
PAGE 77
Input and label
• <!DOCTYPE html>
• <html>
• <body>
• <h2>HTML Forms</h2>
• <form action="/action_page.php">
• <label for="fname">First name:</label><br>
• <input type="text" id="fname" name="fname" value="John"><br>
• <label for="lname">Last name:</label><br>
• <input type="text" id="lname" name="lname" value="Doe"><br>
• <br>
• <input type="submit" value="Submit">
• </form>
• <p>If you click the "Submit" button, the form-data will be sent to a page called
"/action_page.php".</p>
• </body>
• </html> PAGE 78
The <form> Element
The form element can contain one or more of the following form
elements:
PAGE 79
The <input> Element
Type Description
PAGE 80
Radio Buttons
The <input type="radio"> defines a
radio button.
• Radio buttons let a user select ONE of a limited number of choices.
• <form>
<input type="radio" id="male" name="gender" value="male">
<label for="male">Male</label><br>
<input type="radio" id="female" name="gender" value="female">
<label for="female">Female</label><br>
<input type="radio" id="other" name="gender" value="other">
<label for="other">Other</label>
PAGE 81
• <!DOCTYPE html>
• <html>
• <body>
• <form>
• <label for="male">Male</label><br>
• <label for="female">Female</label><br>
• <label for="other">Other</label>
• </form>
• </body>
• </html>
PAGE 82
Checkboxes
• <form>
<input type="checkbox" id="vehicle1" name="vehicle1" value="Bike"
>
<label for="vehicle1"> I have a bike</label><br>
<input type="checkbox" id="vehicle2" name="vehicle2" value="Car">
<label for="vehicle2"> I have a car</label><br>
<input type="checkbox" id="vehicle3" name="vehicle3" value="Boat"
>
<label for="vehicle3"> I have a boat</label> PAGE 83
The Submit Button
The <input type="submit"> defines a button for submitting the form data to a form-handler.
The form-handler is typically a file on the server with a script for processing input data.
• <form action="/action_page.php">
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname" value="John"><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname" value="Doe"><br><br>
<input type="submit" value="Submit">
</form>
PAGE 84
The <select> Element
The <select> element defines a
drop-down list:
• <label for="cars">Choose a car:</label>
<select id="cars" name="cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select> PAGE 85
Allow Multiple Selections:
Use the multiple attribute to allow the user to select more than one value :
PAGE 87
The <fieldset> and <legend> Elements
The <fieldset> element is used to group related data in a form.
The <legend> element defines a caption for the <fieldset>
element.
• <form action="/action_page.php">
<fieldset>
<legend>Personalia:</legend>
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname" value="John"><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname" value="Doe"><br><br>
<input type="submit" value="Submit">
</fieldset>
</form>
PAGE 88
HTML JavaScript
HTML JavaScript
• The <script> element either contains scripting statements, or it points to an external script
• Common uses for JavaScript are image manipulation, form validation, and dynamic
changes of content.
method.
JavaScript Display Possibilities
Example
<!DOCTYPE html>
<html>
<body>
<h1>My First Web Page</h1>
<p>My First Paragraph</p>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = 5 + 6;
</script>
</body>
</html>
Using document.write()
• Using document.write() after an HTML document is fully loaded, will delete all existing HTML:
• Example:ok
<!DOCTYPE html>
<html>
<body>
<h1>My First Web Page</h1>
<p>My first paragraph.</p>
<button type="button" onclick="document.write(5 + 6)">Try it</button>
</body>
</html>
Using window.alert()
• You can use an alert box to display data: ok
<!DOCTYPE html>
<html>
<body>
<h1>My First Web Page</h1>
<p>My first paragraph.</p>
<script>
window.alert(5 + 6);
</script>
</body>
</html>
Using console.log()
• For debugging purposes, you can use the console.log() method to display data.
Example: no
<!DOCTYPE html>
<html>
<body>
<script>
console.log(5 + 6);
</script>
</body>
</html>
Example
• This JavaScript example writes "Hello JavaScript!" into an HTML element with
id="demo":
• Example
• <script>
• document.getElementById("demo").innerHTML = "Hello JavaScript!";
• document.getElementById("demo").style.fontSize = "25px";
• document.getElementById("demo").style.color = "red";
• document.getElementById("demo").style.backgroundColor = "yellow";
• </script>
Try this
• <!DOCTYPE html>
• <html>
• <body>
• <h1>My First JavaScript</h1>
• <p id="demo">JavaScript can change the style of an HTML element.</p>
• <script>
• function myFunction() {
• document.getElementById("demo").style.fontSize = "25px";
• document.getElementById("demo").style.color = "red";
• document.getElementById("demo").style.backgroundColor = "yellow";
• }
• </script>
• <button type="button" onclick="myFunction()">Click Me!</button>
• </body>
• </html>
EXAMPLE
• <!DOCTYPE html>
• <html>
• <body>
• <button type="button"
• onclick="document.getElementById('demo').innerHTML = Date()">
• <p id="demo"></p>
• </body>
• </html>
• jQuery is a JavaScript library which is supported on multiple browsers.
• This also helps to keep the client-side script short and concise.
• This statement tells the browser to write "Hello Dolly." inside an HTML
element with id="demo":
Semicolons ;
• Add a semicolon at the end of each executable statement:
• Example
• document.getElementById("username").disabled = true;
• document.getElementById("password").disabled = true;
• document.getElementById("submit").disabled = true;
JavaScript For Loop
JavaScript Loops
• Loops are handy, if you want to run the same code over and over
again, each time with a different value,Often this is the case when
working with arrays:
Enter Password
• <div >
• <h4 align=“center”>LOGIN</h4>
• <label>Enter Password</label>
• </form>
• </div>
• jQuery is a JavaScript library which is supported on multiple
browsers.
jQuery
creation of powerful and dynamic Web applications.
• This also helps to keep the client-side script short and concise.
• Alternatives to PHP
• Practical extraction and Report Language (Perl)
• Active Server Pages (ASP)
• Java server pages (JSP)
• Ruby
Characteristics
• Open-source
• Multiplatform
HTML/JS Web pages3. PHP interpreter executes PHP script, collects script output and
sends it back
• <head>
• </head>
• <body>
<?php
?>
• </html>
• PHP variables must begin with a “$” sign
• Etc.
• To use or assign variable $ must be present before the name of the
variable
• $A = 1;
• $B = “2”;
• $a * $b // multiplication
• $a / $b // division
if ($foo == 0) {
else {
}
If ... Else...
• No THEN in PHP
While (condition)
}
Date Display
• $datedisplay=date(“yyyy/m/d”);
• Print $datedisplay;
• $datedisplay=date(“l, F m, Y”);
• Print $datedisplay;
• Include “closedb.php”;
• The global variables $_POST[] and $_GET[] contain the request data
<?php
if ($_POST["submit"])
else if ($_POST["cancel"])
?>
• </form>
• Sessions store their identifier in a cookie in the client’s browser
PHP - Sessions
• Every page that uses session data must be proceeded by the session_start()
function
• Session variables are then set and retrieved by accessing the global
$_SESSION[]
• Save it as session.php
<?php
• session_start();
• if (!$_SESSION["count"])
• $_SESSION["count"] = 0;
• if ($_GET["count"] == "yes")
• $_SESSION["count"] = $_SESSION["count"] + 1;
• echo "<h1>".$_SESSION["count"]."</h1>";
• ?>
Sessions session_destroy();
echo "<strong>Step 5 - Destroy This Session
</strong><br />";
if($_SESSION['name']){
echo "The session is still active";
} else {
echo "Ok, the session is no longer active! <br />";
echo "<a href=\".php\"><< Go Back Step 1</a>";
page1
}
?>
Example
• Function: list all tables in your database. Users can select one of
• second.php
• showtable.php
second.php
• html><head><title>MySQL Table Viewer</title></head><body>
• <?php
• // change the value of $dbuser and $dbpass to your username and passw
• $dbhost = 'hercules.cs.kent.edu:3306';
• $dbuser = 'nruan';
• $dbpass = ‘*****************’;
• $dbname = $dbuser;
• $table = 'account';
• $conn = mysql_connect($dbhost, $dbuser, $dbpass);
• if (!$conn) {
• die('Could not connect: ' . mysql_error());
• }
• if (!mysql_select_db($dbname))
• die("Can't select database");
• $result = mysql_query("SHOW TABLES");
• if (!$result) {
• die("Query to show fields from table failed");
second.php
• }
• $num_row = mysql_num_rows($result);
• echo "<h1>Choose one table:<h1>";
• echo "<form action=\"showtable.php\" method=\"POST\">";
• echo "<select name=\"table\" size=\"1\" Font size=\"+2\">";
• for($i=0; $i<$num_row; $i++) {
• $tablename=mysql_fetch_row($result);
• echo "<option value=\"{$tablename[0]}\"
>{$tablename[0]}</option>";
• }
• echo "</select>";
• echo "<div><input type=\"submit\" value=\"submit\"></div>";
• echo "</form>";
• mysql_free_result($result);
• mysql_close($conn);
• ?>
• <html><head>
• <title>MySQL Table Viewer</title>
• </head>
showtable.php • <body>
• <?php
• $dbhost = 'hercules.cs.kent.edu:3306';
• $dbuser = 'nruan';
• $dbpass = ‘**********’;
• $dbname = 'nruan';
• $table = $_POST[“table”];
• $conn = mysql_connect($dbhost, $dbuser, $dbpass);
• if (!$conn)
• die('Could not connect: ' . mysql_error());
• if (!mysql_select_db($dbname))
• die("Can't select database");
• $result = mysql_query("SELECT * FROM {$table}");
• if (!$result) die("Query to show fields from table failed!" .
mysql_error());
• $fields_num = mysql_num_fields($result);
• echo "<h1>Table: {$table}</h1>";
• echo "<table border='1'><tr>";
• // printing table headers
showtable.php
• for($i=0; $i<$fields_num; $i++) {
• $field = mysql_fetch_field($result);
• echo "<td><b>{$field->name}</b></td>";
• }
• echo "</tr>\n";
• while($row = mysql_fetch_row($result)) {
• echo "<tr>";
• // $row is array... foreach( .. ) puts every element
• // of $row to $cell variable
• foreach($row as $cell)
• echo "<td>$cell</td>";
• echo "</tr>\n";
• }
• mysql_free_result($result);
• mysql_close($conn);
• ?>
• </body></html>