ASSIGNMENT Web Programing GTU
ASSIGNMENT Web Programing GTU
Web Programming
(3160713)
B.E. Semester 6
Computer Engineering
CO-1: Use the various HTML tags with appropriate styles to display the various types of
contents effectively.
CO-2: Develop the dynamic web pages using HTML, CSS and JavaScript applying web design
principles to make pages effective.
CO-3: Develop the server side PHP scripts using various features for creating customized web
services.
CO-4: Write the server side scripts for designing web based services with database connectivity.
CO-5: Develop a web application using advanced web programming features including AJAX and JQuery
using concepts of Web API.
ASSIGNMENT
Clients initiate communication by sending requests to servers, which then process these
requests and return the requested information. This model allows for efficient distribution
of tasks, as servers are designed to handle multiple client requests simultaneously.
Additionally, it promotes scalability, as additional clients can be easily accommodated by
adding more server resources.
One of the key advantages of client-server architecture is its flexibility. Clients and servers
can run on different types of hardware and operating systems, enabling interoperability
across diverse environments. Furthermore, it enhances security by centralizing data storage
and access control within the server, reducing the risk of unauthorized access or data loss.
210210107062 1
Government Engineering College, Bhavnagar Web Programming (3160713)
Performance optimization is also vital to minimize page loading times and enhance user
engagement. Designers must optimize images, code, and other elements to improve website
speed and responsiveness, considering factors like caching, compression, and minification.
Security is a fundamental issue in web design, involving protecting websites from threats
like hacking, data breaches, and malware. Designers must implement security measures
such as SSL encryption, secure authentication, and regular software updates to safeguard
sensitive information and maintain user trust.
Additionally, usability and user experience design focus on creating intuitive navigation,
clear layout, and engaging content to enhance user satisfaction and retention. By addressing
these and other issues, web designers can create effective websites that meet the needs of
both clients and users.
3. What is frame set? Explain the use of frame set in web site design with
proper example.
Ans. A frameset is an HTML element used to create a layout that divides a web page into
multiple independent sections, or frames, each containing its own HTML document.
Framesets were commonly used in early web design to achieve layouts with multiple
sections that could be scrolled independently or updated separately.
For example:
<!DOCTYPE html>
<html>
<head>
<title>Frameset Example</title>
</head>
<frameset cols="25%, 75%">
<frame src="menu.html" name="menu">
<frame src="content.html" name="content">
<noframes>
<body>
This page requires a browser that supports frames.
210210107062 2
Government Engineering College, Bhavnagar Web Programming (3160713)
</body>
</noframes>
</frameset>
</html>
In this example, the `<frameset>` element creates two columns, with the first column
occupying 25% of the width and the second column occupying 75%. Within the frameset,
there are two `<frame>` elements, each specifying a separate HTML document to be loaded
into the frame. The `src` attribute of each `<frame>` element points to the HTML files
containing the menu and content of the website, respectively.
When a user visits the webpage, the browser displays the content of the `menu.html` file in
the left frame and the content of the `content.html` file in the right frame. This allows for a
consistent navigation menu to be displayed while the main content of the website changes
based on user interactions, without needing to reload the entire page.
Example:
<p style="color: red; font-size: 16px;">This is a paragraph with inline CSS styling.</p>
Example:
<html>
210210107062 3
Government Engineering College, Bhavnagar Web Programming (3160713)
<head>
<style>
p{
color: blue;
font-size: 18px;
}
</style>
</head>
<body>
<p>This is a paragraph with internal CSS styling.</p>
</body>
</html>
3. External CSS:
External CSS is defined in a separate CSS file and linked to the HTML document using
the `<link>` element. It allows for the separation of content and presentation, making styles
reusable across multiple HTML pages.
Example (style.css):
/* style.css */
p{
color: green;
font-size: 20px;
}
(index.html)
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
210210107062 4
Government Engineering College, Bhavnagar Web Programming (3160713)
Example:
alert("This is an alert box!");
Example:
var result = confirm("Do you want to proceed?");
if (result) {
// User clicked OK
console.log("User confirmed");
} else {
// User clicked Cancel
console.log("User canceled");
}
210210107062 5
Government Engineering College, Bhavnagar Web Programming (3160713)
The `prompt` box is used to prompt the user for input. It displays a message along with a
text input field. It returns the text entered by the user or `null` if they click "Cancel".
Example:
var name = prompt("Please enter your name:", "");
if (name != null && name != "") {
console.log("Hello, " + name + "!");
} else {
console.log("User canceled or did not enter a name.");
}
These pop-up boxes are useful for gathering user input, confirming actions, or providing
important notifications. However, they should be used judiciously to avoid interrupting the
user experience excessively.
Example:
210210107062 6
Government Engineering College, Bhavnagar Web Programming (3160713)
function handleData(data) {
console.log("Received data:", data);
}
fetchData("https://example.com/api/data", handleData);
```
In this example:
• The `fetchData` function takes two parameters: `url` and `callback`. It simulates
fetching data from a server after a delay of 2 seconds using `setTimeout`.
• Once the data is fetched, it calls the `callback` function and passes the fetched data
as an argument.
• The `handleData` function is defined separately as a callback. It receives the
fetched data and logs it to the console.
• Finally, the `fetchData` function is called with the URL and the `handleData`
function as arguments.
Callbacks allow us to define what should happen after a certain task is completed, making
it possible to write asynchronous code in a more organized and readable manner. They are
essential in scenarios where we need to wait for tasks like data retrieval, user input, or event
handling to finish before executing further actions.
Example:
<!DOCTYPE html>
<html>
<head>
<title>Event Handling Example</title>
<script>
210210107062 7
Government Engineering College, Bhavnagar Web Programming (3160713)
function handleClick() {
// Change the text content of the paragraph
document.getElementById("output").textContent = "Button clicked!";
}
function handleKeyPress(event) {
// Check if the pressed key is Enter
if (event.key === "Enter") {
// Change the text content of the paragraph
document.getElementById("output").textContent = "Enter key pressed!";
}
}
</script>
</head>
<body>
<button onclick="handleClick()">Click Me</button>
<input type="text" onkeypress="handleKeyPress(event)">
In this example:
• We define two JavaScript functions: `handleClick` to handle the click event of the
button, and `handleKeyPress` to handle the key press event of the input field.
• Inside the `handleClick` function, we select the `<p>` element with the id "output"
using `document.getElementById` and change its text content to "Button clicked!".
• Inside the `handleKeyPress` function, we check if the pressed key is Enter using
`event.key === "Enter"`. If true, we change the text content of the `<p>` element
to "Enter key pressed!".
• The button and input field have inline event handlers (`onclick` and `onkeypress`)
that call the respective JavaScript functions when the associated events occur.
• The output is displayed in a `<p>` element with the id "output".
210210107062 8
Government Engineering College, Bhavnagar Web Programming (3160713)
Example:
210210107062 9
Government Engineering College, Bhavnagar Web Programming (3160713)
In this example:
- sender.php constructs a query string with the data to be sent (`$name` and `$age`) and
generates a URL containing this query string.
210210107062 10
Government Engineering College, Bhavnagar Web Programming (3160713)
- receiver.php retrieves the data from the query string using the `$_GET` superglobal array
and displays it on the web page.
Using query strings for state management in PHP is straightforward and useful for passing
small amounts of data between pages. However, it's essential to sanitize and validate the
data received from query strings to prevent security vulnerabilities like SQL injection or
cross-site scripting (XSS) attacks.
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "mydatabase";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
?>
210210107062 11
Government Engineering College, Bhavnagar Web Programming (3160713)
Use an HTML form to collect data and insert it into the database.
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = $_POST['name'];
$email = $_POST['email'];
<?php
$sql = "SELECT * FROM users";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
210210107062 12
Government Engineering College, Bhavnagar Web Programming (3160713)
while($row = $result->fetch_assoc()) {
echo "Name: " . $row["name"]. " - Email: " . $row["email"]. "<br>";
}
} else {
echo "0 results";
}
?>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$id = $_POST['id'];
$name = $_POST['name'];
$email = $_POST['email'];
210210107062 13
Government Engineering College, Bhavnagar Web Programming (3160713)
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$id = $_POST['id'];
This example demonstrates a basic implementation of CRUD operations using PHP and
MySQL. It's important to handle user input securely to prevent SQL injection attacks, and
to validate and sanitize data before interacting with the database. Additionally, consider
implementing error handling and validation to provide a robust user experience.
210210107062 14
Government Engineering College, Bhavnagar Web Programming (3160713)
By leveraging AJAX, web developers can create more interactive and responsive web
applications that provide a richer user experience, similar to desktop applications. AJAX is
210210107062 15
Government Engineering College, Bhavnagar Web Programming (3160713)
commonly used in modern web development frameworks and libraries, such as jQuery,
React, Angular, and Vue.js, which provide convenient APIs for making asynchronous
requests and handling responses.
The jQuery syntax is designed to be intuitive and easy to use, employing a simple, chainable
API. Here's a breakdown of jQuery syntax:
Overall, jQuery's concise and expressive syntax streamlines web development and
enhances productivity by reducing the amount of code needed to achieve common tasks.
210210107062 16
Government Engineering College, Bhavnagar Web Programming (3160713)
(ii) ID Selector:
Selects an element with a specific ID attribute.
$('#myElement') // Selects the element with ID "myElement"
210210107062 17
Government Engineering College, Bhavnagar Web Programming (3160713)
210210107062 18