CSE2045Y - Lecture 1 - Review of Web Related Concepts
CSE2045Y - Lecture 1 - Review of Web Related Concepts
Lecture 1
Review of Web Related Concepts
Agenda
• Internet Architecture
• Static v/s Dynamic web pages
• Web Application Framework
– Client Side:
• HTML
• CSS
• JavaScript
– Server Side:
• PHP
• Session
• Database Connection
2
Internet Architecture
• Based on Client/Server model:
– Client: Requests for resources/services
– Server: Provides resources/services to clients
https://i.stack.imgur.com/uKIb7.png
• Server Side:
– PHP
– Sessions
– Database Connection
6
HTML5 Basic Document Structure (1)
http://tutorials.jenkov.com/html5/semantic-elements.html
7
• Nav (<nav>)
– Represents navigation sections of a page. A page can
have more than one navigation section.
• Article (<article>)
– Represents the main content of a page.
– If a page contains multiple contents, each of these
contents can be enclosed in its own article element 8
Other possible HTML5 document structures
A. B.
C. D.
HTML5 Example
10
HTML5 Example
(Browser Output without CSS)
11
HTML5 Example
(Browser Output with CSS)
Javascript Functions
• How to Define a Function?
– To create a function you define its name, any values
("arguments") and some statements
<head>
function myfunction(argument1,argument2)
{
…some statements
}
Return …
</head>
txt_username
txt_password
txt_email
function closeTooltip()
{
div_display_tooltip.innerHTML="";
div_tooltip_id.style.display="inline";
}//end function closeTooltip()
16
Javascript Regular Expression (1)
• Example: Validate numeric
function validateNumeric(val,label)
{
var filter = / ^ [0-9] + $ /;
if (!filter.test(val))
{
alert('Please enter numeric characters for '+ label);
return false;
}
return true;
}//end validateNumeric
17
19
Activity 2
• Based on the requirements given below, write the
regular expression pattern:
– A valid module code should start with only 3 to 4
alphabets in uppercase;
– followed by exactly 4 numbers;
– followed by an optional letter Y
– No other characters should be follow the Y
20
HTML Forms
• Forms are used to send data back to the server for
processing.
• Note:
– The action attribute defines a URL where the data from the form
should be sent to be handled.
– The destination should be a script or other construct capable of
correctly interpreting and doing something useful with the data.
21
22
<fieldset>
<!DOCTYPE html>
<html>
<body>
<fieldset>
<legend>Personal Information</legend>
Name: <input type="text"><br>
Email: <input type="text"><br>
Date of birth: <input type="text">
</fieldset>
</body>
</html>
Date <input>
<label for="txtPostDate">Date</label>
View on Chrome or
Opera browser
Tel <input>
<label for="txtPhone">Phone</label>
Number <input>
<label for="txtNumber">Number</label>
Checkbox <input>
<input type="checkbox" id="chkAgree" name="chkAgree"
required="required"/>
<select>
<label for="sltCar">Car</label>
<select id="sltCar">
<option value="toyota">Toyota</option>
<option value="honda" selected>Honda</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
<textarea>
<label for="txaComments">Comments</label><br>
34
HTML Form example (GET)
<html>
<head><title>hello</title></head>
<body>
<form id= myform action= process.php" method="get">
Name: <input type= text name="txtname />
Password: <input type= password name= txtpass />
<input type= submit name= submit value= login />
<input type= reset name= reset />
</form>
</body>
</html>
35
36
PHP Variables
• All variables in PHP start with a $ sign symbol
$var_name = value;
• There is no need to define the name and type
of the variable before using it.
• PHP automatically converts the variable to the
correct data type, depending on how it is set.
$name= John ;
$code=2003;
37
PHP Forms
• $_GET and $_POST used to obtain information
from the user.
39
40
PHP Database
header( Location: adduser.php?add=yes );
Success
Username:
Password:
process_adduser.php
Name:
Email:
Error
Add user
Added successfully
adduser.php
header( Location: adduser.php?add=no );
41
Activity 3
• Write the section of the codes to display the
message in adduser.php if the GET method is
used.
– If the operation is successful, display Added
successfully .
– Otherwise, display User already exists .
42