WEB 2022 - 2023 Practical Exercises
WEB 2022 - 2023 Practical Exercises
Page 1 of 49
WEB programming
Webseite: https://mateinfo.unitbv.ro/
Practical exercises
TRANSILVANIA UNIVERSITY OF BRASOV
Page 2 of 49
Content
JavaScript .......................................................................................................................................... 16
VRML ................................................................................................................................................. 27
SQL.................................................................................................................................................... 30
PHP ................................................................................................................................................... 41
Practical exercises
TRANSILVANIA UNIVERSITY OF BRASOV
Page 3 of 49
Versions:
Web pages can be created and modified by using professional HTML editors. However, for learning
HTML we recommend a simple text editor like Notepad (PC)
Step 1 - Open Notepad - Start > Programs > Accessories > Notepad
Practical exercises
TRANSILVANIA UNIVERSITY OF BRASOV
Page 4 of 49
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<button>Click me</button>
Step 10 – HTML lists - are defined with the <ul> (unordered/bullet list) or the <ol> (ordered/numbered
list) tag, followed by <li> tags (list items):
<ul>
<li>IAG</li>
<li>MITB</li>
<li>MI</li>
</ul>
Practical exercises
TRANSILVANIA UNIVERSITY OF BRASOV
Page 5 of 49
Step 11 – HTML colors:
Practical exercises
TRANSILVANIA UNIVERSITY OF BRASOV
Page 6 of 49
Step 14 – HTML formating elements were designed to display special types of text:
Practical exercises
TRANSILVANIA UNIVERSITY OF BRASOV
Page 7 of 49
Step 18 – HTML table:
Practical exercises
TRANSILVANIA UNIVERSITY OF BRASOV
Page 8 of 49
EXERCISE 1: Create your own CV in HTML (use all above attributes: image, lists, tables, colors,
heading, fonts, links, background color etc.). The code should be well structured and commented.
Practical exercises
TRANSILVANIA UNIVERSITY OF BRASOV
Page 9 of 49
CSS describes how HTML elements are to be displayed on screen, paper, or in other media.
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
When tags like <font>, and color attributes were added to the HTML 3.2 specification, it started a
nightmare for web developers. Development of large websites, where fonts and color information were
added to every single page, became a long and expensive process.
To solve this problem, the World Wide Web Consortium (W3C) created CSS.
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. However, here we will
use inline and internal styling, because this is easier to demonstrate, and easier for you to try it
yourself.
This example sets the text color of the <h1> element to blue:
Practical exercises
TRANSILVANIA UNIVERSITY OF BRASOV
Page 10 of 49
Step 2 - Internal CSS:
An internal CSS is defined in the <head> section of an HTML page, within a <style> element:
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:
An external style sheet can be written in any text editor. The file must not contain any HTML code, and
must be saved with a .css extension.
Practical exercises
TRANSILVANIA UNIVERSITY OF BRASOV
Page 11 of 49
Step 4 - CSS Fonts:
Example:
Practical exercises
TRANSILVANIA UNIVERSITY OF BRASOV
Page 12 of 49
Step 6 - CSS Padding:
The CSS padding property defines a padding (space) between the text and the border:
The CSS margin property defines a margin (space) outside the border:
To define a specific style for one special element, add an id attribute to the element:
Practical exercises
TRANSILVANIA UNIVERSITY OF BRASOV
Page 13 of 49
Step 9 - The class Attribute:
To define a style for special types of elements, add a class attribute to the element:
External style sheets can be referenced with a full URL or with a path relative to the current web page.
Practical exercises
TRANSILVANIA UNIVERSITY OF BRASOV
Page 14 of 49
EXERCISE 2: Create your own postcard styling HTML with CSS (use all above attributes: lists, tables,
colors, heading, fonts, attributes, icons, imgae gallery etc.). The code should be well structured and
commented.
Side 2:
Practical exercises
TRANSILVANIA UNIVERSITY OF BRASOV
Page 15 of 49
JavaScript
The programs in this language are called scripts. They can be written right in the HTML and execute
automatically as the page loads.
Scripts are provided and executed as a plain text. They don’t need a special preparation or a
compilation to run.
In this aspect, JavaScript is very different from another language called Java. When JavaScript was
created, it initially had another name: “LiveScript”. But Java language was very popular at that time, so
it was decided that positioning a new language as a “younger brother” of Java would help.
At present, JavaScript can execute not only in the browser, but also on the server, or actually on any
device where there exists a special program called the JavaScript engine.
The browser has an embedded engine, sometimes it’s also called a “JavaScript virtual machine”.
• SpiderMonkey – in Firefox.
• …There are other codenames like “Trident”, “Chakra” for different versions of IE,
“ChakraCore” for Microsoft Edge, “Nitro” and “SquirrelFish” for Safari etc.
Combined, these three things exist only in JavaScript and no other browser technology. It’s the most
widespread tool to create browser interfaces.
Links:
Statements: https://www.w3schools.com/js/js_statements.asp
Sytanx: https://www.w3schools.com/js/js_syntax.asp
Variables: https://www.w3schools.com/js/js_variables.asp
Operations: https://www.w3schools.com/js/js_operators.asp
Functions: https://www.w3schools.com/js/js_objects.asp
Objects: https://www.w3schools.com/js/js_objects.asp
Practical exercises
TRANSILVANIA UNIVERSITY OF BRASOV
Page 16 of 49
Practical exercises
TRANSILVANIA UNIVERSITY OF BRASOV
Page 17 of 49
Step 3 – Call index.html file and your browser should open. Following result should be seen:
Practical exercises
TRANSILVANIA UNIVERSITY OF BRASOV
Page 18 of 49
WEB in general - the Most Popular Browsers
Practical exercises
TRANSILVANIA UNIVERSITY OF BRASOV
Page 19 of 49
Safari = Apple Safari (and Konqueror. Both identified as Mozilla before 2007)
Practical exercises
TRANSILVANIA UNIVERSITY OF BRASOV
Page 20 of 49
Browser's developer tools can be used to inspect, edit and debug HTML, CSS, and JavaScript of the
curently-loaded page. To learn more, check out the browser's own manual for developer tools:
Practical exercises
TRANSILVANIA UNIVERSITY OF BRASOV
Page 21 of 49
Web Development Roadmaps
Practical exercises
TRANSILVANIA UNIVERSITY OF BRASOV
Page 22 of 49
Practical exercises
TRANSILVANIA UNIVERSITY OF BRASOV
Page 23 of 49
Example WEB Templates used:
Practical exercises
TRANSILVANIA UNIVERSITY OF BRASOV
Page 24 of 49
Practical exercises
TRANSILVANIA UNIVERSITY OF BRASOV
Page 25 of 49
Links to Templates:
Grayscale: https://startbootstrap.com/template-overviews/grayscale/
Admin: https://startbootstrap.com/template-overviews/sb-admin-2/
Freelancer: https://startbootstrap.com/template-overviews/freelancer/
Creative: https://startbootstrap.com/template-overviews/creative/
Blog: https://startbootstrap.com/template-overviews/clean-blog/
Agency: https://startbootstrap.com/template-overviews/agency/
CV: https://startbootstrap.com/template-overviews/resume/
Practical exercises
TRANSILVANIA UNIVERSITY OF BRASOV
Page 26 of 49
VRML
VRML, the Virtual Reality Modeling Language, is a file format for describing interactive three-
dimensional objects and worlds .
• VRML 1.1 extends VRML to support dynamic input fields, sound, camera-collision, navigation-
info, background, fog, height-fields and prototyping of nodes.
Here a world is a model of a 3D space, which can contain 3D objects, lights, and backgrounds; in
other 3D systems this is often called a scene . Objects can be built from solid shapes, from text, or
from primitive points, lines, and faces. Objects have optical material properties which affects how they
interact with the lights in the world; they can also have textures (2-D pat terns) applied to them.
Objects can be grouped into more complex objects, used multiple times, translated, and rotated.
Objects can trigger events, which can be routed to other events or to scripts written in JavaScript or
Java . Within VRML you can trigger sounds, move objects along paths, and link to HTML or VRML
targets. In JavaScript or Java you can manipulate VRML object properties programmatically and even
generate new objects.
It's entirely possible to create VRML worlds with nothing more than the VRML specification, a text
editor, and a VRML-enabled browser (all of which are free), if you're a programmer with a good grasp
of 3D computer graphics concepts. On the other hand, a VRML modeling program or world builder can
take a lot of the pain out of the process, and make 3D world creation accessible to non-technical
designers.
• Comments and the file header begin with the pound sign, and curly brackets delimit the
hierarchy of nodes and fields.
VRML files measure distance in meters, angles in radians, time in seconds, and colors as RGB triplets
with each value in the range [0.0,1.0]. It uses a Cartesian, right-handed three-dimensional coordinate
system. By default, the viewer is positioned along the positive Z-axis so as to look along the -Z
direction with +Y-axis up.
VRML files use the .wrl (world) extension and the model/vrml MIME type.
The basic node for defining visible VRML objects is the Shape , which in turn contains Geometry and
Appearance nodes.
So, for example, the following example defines a world containing one cylinder 2 meters high with a
1.5 meter radius with default material properties, meaning that the object will appear to be a glowing
white:
Practical exercises
TRANSILVANIA UNIVERSITY OF BRASOV
Page 27 of 49
#VRML V2.0 utf8
# A Cylinder
Shape {
appearance Appearance {
material Material { }
}
geometry Cylinder {
height 2.0
radius 1.5
}
}
The available geometry nodes are the Box, Cone, Cylinder, ElevationGrid, Extrusion,
IndexedFaceSet, IndexedLineSet, PointSet, Sphere and Text .
Fore more detailed information about VRML 2.0 please access: http://www.c3.hu/cryptogram/vrmltut/
Practical exercises
TRANSILVANIA UNIVERSITY OF BRASOV
Page 28 of 49
Step 1 – Write following VRML example. Save the document .wrl:
Practical exercises
TRANSILVANIA UNIVERSITY OF BRASOV
Page 29 of 49
EXERCISE 4: Create your own VRML example (use at least 6 nodes: Box, Cone, Cylinder,
ElevationGrid, Extrusion, IndexedFaceSet, IndexedLineSet, PointSet, Sphere etc.). The code should
be well structured and commented.
Practical exercises
TRANSILVANIA UNIVERSITY OF BRASOV
Page 30 of 49
SQL
SQL is a standard language for storing, manipulating and retrieving data in databases.
What is SQL?
- SQL stands for Structured Query Language
- SQL became a standard of the American National Standards Institute (ANSI) in 1986, and of
the International Organization for Standardization (ISO) in 1987
Practical exercises
TRANSILVANIA UNIVERSITY OF BRASOV
Page 31 of 49
Or access https://www.postgresql.org/
Example of a table that contains five records (one for each customer) and seven columns
(CustomerID, CustomerName, ContactName, Address, City, PostalCode, and Country).:
Practical exercises
TRANSILVANIA UNIVERSITY OF BRASOV
Page 32 of 49
Step 1 – Select Syntax
Step 2 – SQL WHERE clause is used to filter records and to extract only those records that fulfill a
specified condition
The WHERE clause can be combined with AND, OR, and NOT operators.
The AND and OR operators are used to filter records based on more than one condition:
The AND operator displays a record if all the conditions separated by AND is TRUE.
The OR operator displays a record if any of the conditions separated by OR is TRUE.
The ORDER BY keyword is used to sort the result-set in ascending or descending order. The ORDER
BY keyword sorts the records in ascending order by default. To sort the records in descending order,
use the DESC keyword.
Practical exercises
TRANSILVANIA UNIVERSITY OF BRASOV
Page 33 of 49
The INSERT INTO statement is used to insert new records in a table. It is possible to write the
INSERT INTO statement in two ways.
The first way specifies both the column names and the values to be inserted:
If you are adding values for all the columns of the table, you do not need to specify the column names
in the SQL query. However, make sure the order of the values is in the same order as the columns in
the table. The INSERT INTO syntax would be as follows:
The COUNT() function returns the number of rows that matches a specified criteria.
Practical exercises
TRANSILVANIA UNIVERSITY OF BRASOV
Page 34 of 49
Step 8 - SQL MIN() and MAX() Functions:
The MIN() function returns the smallest value of the selected column.
The MAX() function returns the largest value of the selected column.
The SELECT TOP clause is used to specify the number of records to return.
The SELECT TOP clause is useful on large tables with thousands of records. Returning a large
number of records can impact on performance.
Practical exercises
TRANSILVANIA UNIVERSITY OF BRASOV
Page 35 of 49
SQL TOP, LIMIT and ROWNUM Examples:
A JOIN clause is used to combine rows from two or more tables, based on a related column between
them.
Notice that the "CustomerID" column in the "Orders" table refers to the "CustomerID" in the
"Customers" table. The relationship between the two tables above is the "CustomerID" column.
Practical exercises
TRANSILVANIA UNIVERSITY OF BRASOV
Page 36 of 49
Then, we can create the following SQL statement (that contains an INNER JOIN), that selects records
that have matching values in both tables:
Result:
- (INNER) JOIN: Returns records that have matching values in both tables
- LEFT (OUTER) JOIN: Return all records from the left table, and the matched records from the
right table
- RIGHT (OUTER) JOIN: Return all records from the right table, and the matched records from
the left table
- FULL (OUTER) JOIN: Return all records when there is a match in either left or right table
The INNER JOIN keyword selects records that have matching values in both tables.
Practical exercises
TRANSILVANIA UNIVERSITY OF BRASOV
Page 37 of 49
Step 12 - SQL LEFT JOIN Keyword:
The LEFT JOIN keyword returns all records from the left table (table1), and the matched records from
the right table (table2). The result is NULL from the right side, if there is no match.
The RIGHT JOIN keyword returns all records from the right table (table2), and the matched records
from the left table (table1). The result is NULL from the left side, when there is no match.
The FULL OUTER JOIN keyword return all records when there is a match in either left (table1) or right
(table2) table records.
Note: FULL OUTER JOIN can potentially return very large result-sets!
The GROUP BY statement is often used with aggregate functions (COUNT, MAX, MIN, SUM, AVG) to
group the result-set by one or more columns.
Practical exercises
TRANSILVANIA UNIVERSITY OF BRASOV
Page 38 of 49
Tip: Make sure you have admin privilege before creating any database. Once a database is created,
you can check it in the list of databases with the following SQL command: SHOW DATABASES.
The column parameters specify the names of the columns of the table.
The datatype parameter specifies the type of data the column can hold (e.g. varchar, integer, date,
etc.).
The PRIMARY KEY constraint uniquely identifies each record in a database table.
Primary keys must contain UNIQUE values, and cannot contain NULL values.
A FOREIGN KEY is a field (or collection of fields) in one table that refers to the PRIMARY KEY in
another table.
Practical exercises
TRANSILVANIA UNIVERSITY OF BRASOV
Page 39 of 49
The table containing the foreign key is called the child table, and the table containing the candidate
key is called the referenced or parent table.
"Persons" table:
"Orders" table:
Notice that the "PersonID" column in the "Orders" table points to the "PersonID" column in the
"Persons" table.
The "PersonID" column in the "Persons" table is the PRIMARY KEY in the "Persons" table.
The "PersonID" column in the "Orders" table is a FOREIGN KEY in the "Orders" table.
The FOREIGN KEY constraint is used to prevent actions that would destroy links between tables.
The FOREIGN KEY constraint also prevents invalid data from being inserted into the foreign key
column, because it has to be one of the values contained in the table it points to.
The following SQL creates a FOREIGN KEY on the "PersonID" column when the "Orders" table is
created:
Practical exercises
TRANSILVANIA UNIVERSITY OF BRASOV
Page 40 of 49
EXERCISE 5: Create your own two tables, binding them via keys, define your fields (simple
structures, didactic applications, catalog, student data etc.). Insert data by using the statement
INSERT INTO. Create simple SELECT statements.
Use the tables you created in exercise 1. Create simple SQL statements using COUNT, AVG, SUM,
MAX or LIMIT.
Create your own two or three tables, binding them via keys, define your fields (simple structures,
didactic applications, catalog, student data etc.). Insert data and create different JOIN statement
using all types (RIGHT, LEFT etc.).
Practical exercises
TRANSILVANIA UNIVERSITY OF BRASOV
Page 41 of 49
PHP
It is powerful enough to be at the core of the biggest blogging system on the web (WordPress)!
Why PHP?
PHP runs on various platforms (Windows, Linux, Unix, Mac OS X, etc.)
PHP is compatible with almost all servers used today (Apache, IIS, etc.)
PHP supports a wide range of databases
PHP is free. Download it from the official PHP resource: www.php.net
PHP is easy to learn and runs efficiently on the server side
With PHP you are not limited to output HTML. You can output images, PDF files, and even Flash
movies. You can also output any text, such as XHTML and XML.
- install PHP
The official PHP website (PHP.net) has installation instructions for PHP:
http://php.net/manual/en/install.php
Practical exercises
TRANSILVANIA UNIVERSITY OF BRASOV
Page 42 of 49
Step 2 – PHP Syntax
A PHP file normally contains HTML tags, and some PHP scripting code.
In the example below, only the first statement will display the value of the $color variable (this is
because $color, $COLOR, and $coLOR are treated as three different variables):
Practical exercises
TRANSILVANIA UNIVERSITY OF BRASOV
Page 43 of 49
Step 3 - PHP Variables
In PHP, a variable starts with the $ sign, followed by the name of the variable:
A variable can have a short name (like x and y) or a more descriptive name (age, carname,
total_volume).
• A variable starts with the $ sign, followed by the name of the variable
• A variable name must start with a letter or the underscore character
• A variable name cannot start with a number
• A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9 and _ )
• Variable names are case-sensitive ($age and $AGE are two different variables)
In PHP, variables can be declared anywhere in the script. The scope of a variable is the part of the
script where the variable can be referenced/used.
• local
• global
• static
Practical exercises
TRANSILVANIA UNIVERSITY OF BRASOV
Page 44 of 49
• String
• Integer
• Float (floating point numbers - also called double)
• Boolean
• Array
• Object
• NULL
• Resource
Step 5 – Constants
A constant is an identifier (name) for a simple value. The value cannot be changed during the script.
A valid constant name starts with a letter or underscore (no $ sign before the constant name).
Note: Unlike variables, constants are automatically global across the entire script.
Syntax
• define(name, value, case-insensitive)
Parameters:
Practical exercises
TRANSILVANIA UNIVERSITY OF BRASOV
Page 45 of 49
Step 6 – Operators
• Arithmetic operators
• Assignment operators
• Comparison operators
• Increment/Decrement operators
• Logical operators
• String operators
Practical exercises
TRANSILVANIA UNIVERSITY OF BRASOV
Page 46 of 49
Step 7 – Functions
Besides the built-in PHP functions, we can create our own functions.
Practical exercises
TRANSILVANIA UNIVERSITY OF BRASOV
Page 47 of 49
Step 8 – Date and Time
The PHP date() function formats a timestamp to a more readable date and time:
Here are some characters that are commonly used for dates:
• d - Represents the day of the month (01 to 31)
• m - Represents a month (01 to 12)
• Y - Represents a year (in four digits)
• l (lowercase 'L') - Represents the day of the week
Other characters, like"/", ".", or "-" can also be inserted between the characters to add additional
formatting.
The default error handling in PHP is very simple. An error message with filename, line number and a
message describing the error is sent to the browser.
When creating scripts and web applications, error handling is an important part. If your code lacks
error checking code, your program may look very unprofessional and you may be open to security
risks.
The first example shows a simple script that opens a text file:
Practical exercises
TRANSILVANIA UNIVERSITY OF BRASOV
Page 48 of 49
Syntax:
In this example, an error occurs if the "test" variable is bigger than "1":
An error can be triggered anywhere you wish in a script, and by adding a second parameter, you can
specify what error level is triggered.
• E_USER_ERROR - Fatal user-generated run-time error. Errors that can not be recovered
from. Execution of the script is halted
• E_USER_WARNING - Non-fatal user-generated run-time warning. Execution of the script is
not halted
• E_USER_NOTICE - Default. User-generated run-time notice. The script found something that
might be an error, but could also happen when running a script normally
Practical exercises
TRANSILVANIA UNIVERSITY OF BRASOV
Page 49 of 49
EXERCISE 5: Create your own php example using Validate E-mail and URL function
(https://www.w3schools.com/php/php_form_url_email.asp). If entered email is wrong, show error
message.
Practical exercises