Wpassignment
Wpassignment
Assignment
CO-1: Use the various HTML tags with appropriate styles to display the
various types of contents effectively.
Q.1) What are semantic HTML tags? Provide examples and explain their importance in
SEO and accessibility.
Ans. Semantic HTML tags are elements that clearly define the meaning of the content they contain. Unlike
non-semantic tags (e.g., <div> and <span>), which do not provide any context about their content, semantic
tags improve readability, accessibility, and search engine optimization (SEO).
1. <header> – Represents the introductory content or navigational links of a webpage.
<header>
<h1>Welcome to My Website</h1>
<ul>
<li><a href="#">Home</a></li>
</ul>
</header>
2. <nav> – Defines a section for navigation links.
<nav>
<ul>
<li><a href="#">Services</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
3. <footer> – Defines the footer section of a webpage, usually containing copyright information, links, or
contact details.
<footer>
<p> 2025 MyWebsite. All rights reserved.</p>
</footer>
Importance of Semantic HTML in SEO and Accessibility
C.E., LDCE 1
BHAYALA ABDULREHMAN
220280107008
1. SEO Benefits
• Helps search engines understand page structure, improving indexing and ranking.
• Increases the chances of content appearing in rich snippets.
• Enhances readability for search engine crawlers.
2. Accessibility Benefits
• Improves user experience for screen readers and assistive technologies.
• Helps visually impaired users navigate web content easily.
• Ensures a structured and meaningful layout for all users.
3. Maintainability and Readability
• Makes the code more readable and maintainable for developers.
• Reduces the need for excessive div elements (commonly known as "div soup").
Q.2) What is the box model in CSS? Explain the different components of the box model.
Ans. The CSS Box Model is a fundamental concept that defines how elements are structured and
displayed on a webpage. It consists of four main components: Content, Padding, Border, and
Margin, each contributing to the overall size and spacing of an element.
1. Content
• This is the innermost part of the box where text, images, or other elements are placed.
• Its size is controlled by width and height properties.
2. Padding
3. Border
• Wraps around the padding and content, defining the outer edge of the box.
• Can be styled using properties like border-width, border-style, and border-color.
4. Margin
• The space outside the border that separates the element from other elements.
• Used for spacing between elements.
C.E., LDCE 2
220280107008 BHAYALA ABDULREHMAN
Q.3) What is the difference between class and id in CSS? Provide examples of when to use
each.
Ans.
Multiplicity An element can have multiple classes An element can have only one id
C.E., LDCE 3
220280107008 BHAYALA ABDULREHMAN
color: white;
}
</style>
</head>
<body>
<button class="button">Submit</button>
<button class="button">Cancel</button>
</body>
</html>
Using ID (#) - When Styling a Unique Element
An ID is meant for a single element that should have a unique style.
<html lang="en">
<head>
<style>
#main-title {
font-size: 24px;
color: darkgreen;
}
</style>
</head>
<body>
<h1 id="main-title">Welcome to My Website</h1>
</body>
</html>
Q.4) What is the purpose of the z-index property in CSS? How does it affect positioning?
Ans. The z-index property in CSS is used to control the stacking order of overlapping elements. It
determines which elements appear in front and which ones appear behind when they overlap on a
webpage.
C.E., LDCE 4
220280107008 BHAYALA ABDULREHMAN
C.E., LDCE 5
BHAYALA ABDULREHMAN
220280107008
Q.5) How would you create a responsive web page layout that adjusts to different screen sizes
using CSS? Explain the use of media queries.
Ans. Techniques for Responsive Design
1. Fluid Layouts – Using relative units (%, vw, vh) instead of fixed units (px).
2. Flexible Images – Ensuring images resize with max-width: 100%.
3. CSS Flexbox & Grid – Creating adaptable layouts.
4. Media Queries – Applying different styles based on screen width.
Media queries allow you to apply CSS rules conditionally based on screen width, height, orientation, or
device type.
@media (max-width: 768px) {
/* CSS rules for screens 768px or smaller */
}
Q.6) Explain the differences between inline, block, and inline-block elements in CSS with
examples.
Ans.
Starts on a new
No Yes No
line?
Margin & Padding Partial (horizontal Yes (both horizontal & Yes (both horizontal &
Work? only) vertical) vertical)
1. Inline:
<html lang="en">
<head>
C.E., LDCE 6
220280107008 BHAYALA ABDULREHMAN
<style>
span {
background-color: lightblue;
width: 200px; /* Won't work */
padding: 10px; /* Works, but only horizontally */
}
</style>
</head>
<body>
<p>This is an <span>inline element</span> inside a paragraph.</p>
</body>
</html>
2. Block:
<!DOCTYPE html>
<html lang="en">
<head>
<style>
div {
background-color: lightcoral;
width: 300px;
height: 100px;
}
</style>
</head>
<body>
<div>This is a block element.</div>
<div>Another block element below.</div>
</body>
C.E., LDCE 7
220280107008 BHAYALA ABDULREHMAN
</html>
3. Inline Block:
<!DOCTYPE html>
<html lang="en">
<head>
<style>
.inline-block {
display: inline-block;
background-color: lightgreen;
width: 200px;
height: 100px;
}
</style>
</head>
<body>
<div class="inline-block">Box 1</div>
<div class="inline-block">Box 2</div>
</body>
</html>
Q.7) What are pseudo-classes in CSS? List some commonly used pseudo-classes and explain
their functions.
Ans. A pseudo-class in CSS is a special keyword added to a selector that defines a specific state of
an element. It allows styling elements based on user interactions, position in the document, or their
current state without modifying the HTML structure.
Syntax:
selector:pseudo-class {
property: value;
}
C.E., LDCE 8
220280107008 BHAYALA ABDULREHMAN
Q.8) How do you center a div element horizontally and vertically using CSS?
Ans. Flexbox is the easiest and most modern way to center a div.
.container {
display: flex;
justify-content: center; /* Centers horizontally */
align-items: center; /* Centers vertically */
height: 100vh; /* Full viewport height */
background-color: lightgray;
}
Q.9) What is the difference between the visibility: hidden and display: none properties in CSS?
Ans.
C.E., LDCE 9
220280107008 BHAYALA ABDULREHMAN
CO-2: Develop the dynamic web pages using HTML, CSS and JavaScript
applying web design principles to make pages effective.
Q.1) Explain the difference between let, const, and var in JavaScript. When would you use
each?
Ans.
Q.2) What is a closure in JavaScript? Provide an example to illustrate how closures work.
Ans. A closure in JavaScript is a function that remembers the variables from its outer scope even after the
outer function has finished executing. This allows inner functions to access and manipulate variables from
an enclosing function's scope, even after the enclosing function has returned.
function outerFunction(name) {
let greeting = "Hello, ";
C.E., LDCE 10
BHAYALA ABDULREHMAN
220280107008
Explanation:
• outerFunction("John") executes, storing "Hello, " in greeting.
• It returns innerFunction, which remembers greeting and name even after outerFunction has
finished execution.
• When greetJohn() is called later, it still has access to greeting, demonstrating a closure.
Q.4) What is the difference between == and === in JavaScript? Provide examples.
C.E., LDCE 11
BHAYALA ABDULREHMAN
220280107008
Ans.
Eg. Of == :
console.log(5 == "5"); // true (string "5" is converted to number 5)
console.log(0 == false); // true (false is converted to 0)
console.log(null == undefined); // true (both are treated as "empty" values)
console.log(1 == true); // true (true is converted to 1)
Eg. Of === :
console.log(5 === "5"); // false (different types: number vs. string)
console.log(0 === false); // false (different types: number vs. boolean)
console.log(null === undefined); // false (different types)
console.log(1 === true); // false (number vs. boolean)
console.log(5 === 5); // true (same type and value)
Q.5) Describe the event bubbling and event capturing phases in JavaScript event handling.
How do you stop event propagation?
Ans. 1. Event Bubbling (Default Behavior)
• The event starts from the target element and bubbles upward through its parent elements.
• Inner elements trigger events first, followed by their ancestors.
Example of Event Bubbling:
<div id="parent" style="padding: 20px; background-color: lightblue;">
<button id="child">Click Me</button>
</div>
<script>
document.getElementById("parent").addEventListener("click", () => {
console.log("Parent Div Clicked!");
C.E., LDCE 12
220280107008 BHAYALA ABDULREHMAN
});
document.getElementById("child").addEventListener("click", () => {
console.log("Child Button Clicked!");
});
</script>
Output when clicking the button (child):
Child Button Clicked!
Parent Div Clicked!
2. Event Capturing (Trickling Down)
• The event starts from the root element and trickles down to the target element.
• To enable capturing, pass { capture: true } as the third argument in addEventListener().
Example of Event Capturing:
document.getElementById("parent").addEventListener("click", () => {
console.log("Parent Div Clicked!");
}, true); // Capturing mode
document.getElementById("child").addEventListener("click", () => {
console.log("Child Button Clicked!");
}, true); // Capturing mode
Output when clicking the button (child):
Parent Div Clicked!
Child Button Clicked!
• event.stopPropagation()
Stops event bubbling or capturing at the current level.
Example:
document.getElementById("child").addEventListener("click", (event) => {
console.log("Child Button Clicked!");
event.stopPropagation(); // Stops the event from reaching the parent
C.E., LDCE 13
220280107008
BHAYALA ABDULREHMAN
});
Q.6) How do you handle form validation using JavaScript? Provide an example of client-side
validation for an email input.
Ans. Types of Form Validation
1. Built-in HTML Validation (e.g., required, pattern, minlength)
2. JavaScript Client-Side Validation (custom logic for checking input)
3. Server-Side Validation (for security, as JavaScript can be bypassed)
Example: Client-Side Email Validation
<html lang="en">
<head>
<title>Email Validation</title>
<style>
.error { color: red; }
</style>
</head>
<body>
<form id="myForm">
<label for="email">Email:</label>
<input type="text" id="email" name="email">
<span id="emailError" class="error"></span>
<br><br>
<button type="submit">Submit</button>
</form>
<script>
document.getElementById("myForm").addEventListener("submit", function(event) {
event.preventDefault(); // Prevent form from submitting
C.E., LDCE 14
220280107008
BHAYALA ABDULREHMAN
} else {
emailError.textContent = "";
alert("Form submitted successfully!");
// You can submit the form using `this.submit();`
}
});
</script>
</body>
</html>
Q.7) Explain the difference between synchronous and asynchronous JavaScript operations.
What is the purpose of Promise in handling asynchronous code?
Ans. 1️ Synchronous JavaScript (Blocking)
• Code runs line by line, waiting for each operation to finish before proceeding.
• Blocking behavior can make the application unresponsive.
Example: Synchronous Code
console.log("Step 1");
alert("Blocking Alert!"); // Execution pauses here until user closes alert
console.log("Step 2"); // Runs only after alert is closed
Output:
Step 1
(Alert appears)
Step 2 (Runs after alert is closed)
C.E., LDCE 15
BHAYALA ABDULREHMAN
220280107008
C.E., LDCE 16
220280107008 BHAYALA ABDULREHMAN
fetchData()
.then((message) => console.log(message)) // Runs if resolved
.catch((error) => console.error(error)); // Runs if rejected
console.log("Other operations continue...");
Output:
Fetching data...
Other operations continue...
(Data fetched successfully! after 2 seconds)
Q.8) What are JavaScript arrays? How would you add, remove, and modify elements in an
array? Provide examples.
Ans. An array in JavaScript is a data structure used to store multiple values in a single variable. Arrays
can hold different data types, including numbers, strings, objects, and even other arrays (nested arrays).
Declaring an Array
let fruits = ["Apple", "Banana", "Cherry"]; // Array of strings
let numbers = [10, 20, 30, 40]; // Array of numbers
let mixed = ["Text", 100, true, { key: "value" }]; // Mixed data types
C.E., LDCE 17
BHAYALA ABDULREHMAN
220280107008
Q.10) What is DOM manipulation? Write JavaScript code to change the content of a div
element when a button is clicked.
Ans. DOM (Document Object Model) manipulation is the process of dynamically changing the
structure, content, or style of an HTML document using JavaScript. It allows us to add, remove, or
modify elements and attributes in real-time.
<!DOCTYPE html>
<html lang="en">
C.E., LDCE 18
220280107008
BHAYALA ABDULREHMAN
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>DOM Manipulation Example</title>
<style>
#content {
font-size: 20px;
color: blue;
padding: 10px;
}
</style>
</head>
<body>
<script>
function changeText() {
document.getElementById("content").innerHTML = "Content Updated!";
}
</script>
</body>
</html>
C.E., LDCE 19
BHAYALA ABDULREHMAN
220280107008
CO-3: Develop the server side PHP scripts using various features for
creating customized web services.
Q.1) Explain the difference between include() and require() in PHP. When would you use
each function?
Ans.
Q.2) How do you connect to a MySQL database using PHP? Write a basic PHP script to
connect to a database and display a message if successful.
Ans. To connect to a MySQL database in PHP, we typically use the MySQLi (MySQL Improved)
extension or PDO (PHP Data Objects). Below is an example using MySQLi.
<?php
// Database connection details
$servername = "localhost"; // Server name (use an IP address or domain if remote)
$username = "root"; // Database username
$password = ""; // Database password (leave blank if no password)
$database = "test_db"; // Name of the database
// Create connection
$conn = new mysqli($servername, $username, $password, $database);
C.E., LDCE 20
BHAYALA ABDULREHMAN
220280107008
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
Q.3) What is a session in PHP? How do you create, access, and destroy a session in PHP?
Ans. A session in PHP is a way to store user information across multiple pages. Unlike cookies, session
data is stored on the server instead of the user's browser, making it more secure.
<?php
if (!isset($_SESSION["username"])) {
$_SESSION["username"] = "JohnDoe";
$_SESSION["role"] = "Admin";
} else {
if (isset($_GET['logout'])) {
C.E., LDCE 21
220280107008
BHAYALA ABDULREHMAN
exit();
?>
Q.4) What is the purpose of $_GET and $_POST in PHP? Provide examples of how data can
be sent and received using these superglobals.
Ans.
<?php
if (isset($_GET["name"])) {
echo "Hello, " . htmlspecialchars($_GET["name"]);
} else {
C.E., LDCE 22
220280107008
get_example.php?name=John
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (!empty($_POST["name"])) {
echo "Hello, " . htmlspecialchars($_POST["name"]);
} else {
echo "Please enter your name.";
}
}
?>
Q.5) Explain the concept of form handling in PHP. How do you handle file uploads using
PHP?
Ans. Form handling in PHP involves collecting, processing, and validating user input from HTML forms.
PHP uses the $_GET, $_POST, and $_FILES superglobals to manage form data.
C.E., LDCE 23
220280107008 BHAYALA ABDULREHMAN
C.E., LDCE 24
220280107008 BHAYALA ABDULREHMAN
Ans. A cookie is a small piece of data stored on the user's browser. PHP uses cookies to store information
like user preferences, login status, or session identifiers.
<?php
$cookie_name = "username";
$cookie_value = "JohnDoe";
$cookie_expiration = time() + (86400 * 7); // Cookie expires in 7 days
C.E., LDCE 25
220280107008 BHAYALA ABDULREHMAN
Q.7) What is the difference between foreach(), for(), and while() loops in PHP? When would
you use each?
Ans. 1️ foreach() Loop
Syntax:
Example:
<?php
$fruits = ["Apple", "Banana", "Cherry"];
foreach ($fruits as $fruit) {
echo $fruit . "<br>";
}
?>
🔹 When to Use?
2️ for() Loop
C.E., LDCE 26
220280107008
BHAYALA ABDULREHMAN
Syntax:
Example:
<?php
for ($i = 1; $i <= 5; $i++) {
echo "Number: " . $i . "<br>";
}
?>
🔹 When to Use?
3️ while() Loop
Syntax:
while (condition) {
// Code to execute
}
Example:
<?php
$number = 1;
while ($number <= 5) {
echo "Number: " . $number . "<br>";
$number++;
}
?>
🔹 When to Use?
C.E., LDCE 27
220280107008 BHAYALA ABDULREHMAN
Q.8) What is an associative array in PHP? How does it differ from an indexed array?
Ans. An associative array in PHP uses named keys (strings) instead of numbers to identify elements.
<?php
$person = [
"name" => "John",
"age" => 25,
"city" => "New York"
];
Q.9) What is the use of the isset() and empty() functions in PHP?
Ans.
Q.10) Explain the concept of object-oriented programming (OOP) in PHP. How do you
create a class and instantiate objects in PHP?
C.E., LDCE 28
220280107008 BHAYALA ABDULREHMAN
Ans. Object-Oriented Programming (OOP) is a programming paradigm that uses objects and classes to
structure code. It helps in organizing complex programs by encapsulating data and behavior together.
<?php
class Car {
// Properties
public $brand;
public $color;
// Constructor Method
public function __construct($brand, $color) {
$this->brand = $brand;
$this->color = $color;
}
// Method to Display Car Details
public function displayCar() {
echo "This car is a $this->color $this->brand.<br>";
}
}
?>
<?php
// Creating objects of Car class
$car1 = new Car("Toyota", "Red");
$car2 = new Car("Honda", "Blue");
// Calling method
$car1->displayCar(); // Output: This car is a Red Toyota.
$car2->displayCar(); // Output: This car is a Blue Honda.
?>
C.E., LDCE 29
220280107008 BHAYALA ABDULREHMAN
CO-4: Write the server side scripts for designing web based services with
database connectivity.
Q.1) What are the functions used to connect to a MySQL database in PHP?
Ans.
Q.2) Write a PHP script to connect to a MySQL database using mysqli and check if the
connection is successful.
Ans. <?php
// Database configuration
$servername = "localhost";
$username = "root";
$password = ""; // Update if your MySQL has a password
$database = "your_database_name"; // Replace with your database name
// Create connection
$conn = new mysqli($servername, $username, $password, $database);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully!";
?>
Q.3) Explain the difference between mysqli and PDO for database connectivity in PHP.
Which one is preferred for new projects and why?
C.E., LDCE 30
220280107008 BHAYALA ABDULREHMAN
Features:
- Supports only MySQL databases
- Offers both Procedural & Object-Oriented approaches
-Supports prepared statements (better security)
- Has faster execution for simple queries
Limitations:
-Works only with MySQL (not portable to other databases)
-Slightly less flexible than PDO
-Lacks advanced database abstraction
if ($mysqli->connect_error) {
die("Connection failed: " . $mysqli->connect_error);
}
Features:
-Works with multiple databases (MySQL, PostgreSQL, SQLite, etc.)
-Uses only Object-Oriented approach
-Fully supports prepared statements (prevents SQL injection)
-Provides advanced error handling using exceptions
Limitations:
-Can be slightly slower than MySQLi for simple queries
-More complex syntax compared to MySQLi
try {
$pdo = new PDO("mysql:host=localhost;dbname=test_db", "root", "");
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected successfully!";
} catch (PDOException $e) {
echo "Connection failed: " . $e->getMessage();
}
C.E., LDCE 31
BHAYALA ABDULREHMAN
220280107008
1. Database Flexibility: Works with multiple databases (MySQL, PostgreSQL, SQLite, etc.),
making future migrations easier.
2. Better Security: Uses prepared statements by default, preventing SQL injection.
3. Advanced Error Handling: Uses exceptions for better debugging and error management.
Q.4) What is the purpose of the mysqli_select_db() function in PHP? Provide an example.
Ans. The mysqli_select_db() function is used to select a specific database after establishing a connection
to a MySQL server. It allows you to switch between multiple databases without reconnecting.
<?php
// Database connection
$servername = "localhost";
$username = "root";
$password = "";
$conn = mysqli_connect($servername, $username, $password);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
// Select a database
if (mysqli_select_db($conn, "test_database")) {
echo "Database selected successfully!";
} else {
echo "Failed to select database: " . mysqli_error($conn);
}
// Close the connection
mysqli_close($conn);
?>
C.E., LDCE 32
220280107008 BHAYALA ABDULREHMAN
Q.5) Write a PHP script to insert a record into a MySQL database using mysqli (
without prepared statements).
Ans. <?php
// Database connection
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "test_database";
// Connect to MySQL
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
// Insert query
$name = "John Doe";
$email = "john@example.com";
$mobile = "9876543210";
$sql = "INSERT INTO users (name, email, mobile) VALUES ('$name', '$email', '$mobile')";
C.E., LDCE 33
220280107008 BHAYALA ABDULREHMAN
mysqli_close($conn);
?>
Q.6) What is SQL injection? How can you prevent SQL injection when inserting data into a
database in PHP?
Ans. SQL Injection is a web security vulnerability where an attacker manipulates an SQL query by
injecting malicious SQL code into an input field. This can allow unauthorized access, data leaks, or even
deletion of entire databases.
Prepared statements separate SQL logic from user input, preventing SQL injection.
php
CopyEdit
<?php
$conn = mysqli_connect("localhost", "root", "", "test_database");
$username = $_POST['username'];
$password = $_POST['password'];
$result = $stmt->get_result();
?>
Why it’s safe? The user input is treated as data, not part of the SQL query.
php
CopyEdit
$username = mysqli_real_escape_string($conn, $_POST['username']);
C.E., LDCE 34
BHAYALA ABDULREHMAN
220280107008
$sql = "SELECT * FROM users WHERE username = '$username' AND password = '$password'";
Warning: This is better than nothing, but prepared statements are much safer.
php
CopyEdit
$email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
php
CopyEdit
if (!ctype_alnum($_POST['username'])) {
die("Invalid username!");
}
Q.7) Write a PHP script to fetch all records from the users table using mysqli and display
them in a table.
Ans. <?php
// Database connection
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "test_database";
// Connect to MySQL
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
C.E., LDCE 35
BHAYALA ABDULREHMAN
220280107008
C.E., LDCE 36
BHAYALA ABDULREHMAN
220280107008
Q.8) Write a PHP script to fetch a single record from the users table by a specific user_id
using mysqli.
Ans. <?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "test_database";
$conn = mysqli_connect($servername, $username, $password, $dbname);
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$user_id = isset($_GET['id']) ? intval($_GET['id']) : 0;
$sql = "SELECT * FROM users WHERE id = $user_id";
C.E., LDCE 37
BHAYALA ABDULREHMAN
220280107008
Q.9) Write a PHP script to update a record in the users table using mysqli (without
prepared statements).
Ans. <?php
C.E., LDCE 38
220280107008 BHAYALA ABDULREHMAN
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "test_database";
$conn = mysqli_connect($servername, $username, $password, $dbname);
if (!$conn) { die("Connection failed: " . mysqli_connect_error()); }
$user_id = isset($_GET['id']) ? intval($_GET['id']) : 0;
$sql = "SELECT * FROM users WHERE id = $user_id";
$result = mysqli_query($conn, $sql);
$user = mysqli_fetch_assoc($result);
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = $_POST['name'];
$email = $_POST['email'];
$mobile = $_POST['mobile'];
$update_sql = "UPDATE users SET name='$name', email='$email', mobile='$mobile' WHERE
id=$user_id";
echo mysqli_query($conn, $update_sql) ? "Record updated successfully." : "Error updating
record: " . mysqli_error($conn);
}
mysqli_close($conn);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Update User</title>
C.E., LDCE 39
220280107008
BHAYALA ABDULREHMAN
</head>
<body>
<h2>Update User</h2>
<?php if ($user): ?>
<form method="post">
<label>Name:</label>
<input type="text" name="name" value="<?php echo htmlspecialchars($user['name']); ?>"
required><br><br>
<label>Email:</label>
<input type="email" name="email" value="<?php echo htmlspecialchars($user['email']); ?>"
required><br><br>
<label>Mobile:</label>
<input type="text" name="mobile" value="<?php echo htmlspecialchars($user['mobile']);
?>" required><br><br>
<button type="submit">Update</button>
</form>
<?php else: ?>
<p>User not found.</p>
<?php endif; ?>
</body>
</html>
Q.10) What is a stored procedure, and how is it different from regular SQL queries?
Ans. A stored procedure is a precompiled collection of SQL statements that is stored in a database and
can be executed multiple times with different parameters. It helps in automating tasks, improving
performance, and increasing security.
C.E., LDCE 40
220280107008 BHAYALA ABDULREHMAN
A predefined SQL script stored in the A single SQL command or query executed
Definition
database manually
Execution Called using CALL procedure_name() Directly executed in the SQL engine
Provides controlled access to database Users must have direct access to the database
Security
operations tables
Q.11) Explain how you would pass parameters to a stored procedure in MySQL using PHP.
Ans. Steps to Pass Parameters
DELIMITER //
CREATE PROCEDURE GetUserById(IN user_id INT)
BEGIN
SELECT * FROM users WHERE id = user_id;
END //
DELIMITER ;
C.E., LDCE 41
220280107008 BHAYALA ABDULREHMAN
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "test_database";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); }
if ($user) {
echo "User Found: " . $user['name'] . " - " . $user['email'];
} else {
echo "No user found.";
}
$stmt->close();
$conn->close();
?>
Q.12) What is the difference between a function and a stored procedure in MySQL? Can a
stored procedure return a value?
Ans.
C.E., LDCE 42
220280107008 BHAYALA ABDULREHMAN
Q.1) What is the difference between synchronous and asynchronous web programming?
Ans.
Benefit Explanation
Prevents the application from freezing while waiting for tasks like API calls
1️ Non-Blocking Execution
or database queries.
2️ Improved Performance Multiple tasks can execute simultaneously, reducing overall processing time.
Ensures smooth UI interactions by running background tasks without
3️ Better User Experience
affecting user interactions.
Enables live notifications, chat systems, and stock price updates without
4️ Real-Time Updates
page reloads.
5️ Efficient Resource Servers can handle multiple requests at once (important for Node.js and
Utilization high-traffic applications).
6️ Faster Data Fetching Speeds up API requests and database queries, making web pages load faster.
C.E., LDCE 43
220280107008 BHAYALA ABDULREHMAN
Ans. The event loop is a mechanism in JavaScript and Node.js that allows non-blocking execution of
tasks. It ensures that JavaScript can handle multiple operations without freezing the application.
Q.4) What are the key benefits of using asynchronous web programming in web
development?
Ans.
Benefit Explanation
Allows tasks to run in the background while other operations
1️ Non-Blocking Execution
continue.
2️ Faster Performance Multiple operations can execute simultaneously, reducing wait time.
3️ Better User Experience Keeps the UI responsive, preventing page freezing.
4️ Efficient API Calls Handles multiple API requests without waiting for each to finish.
5️ Real-Time Updates Enables live chat, notifications, stock prices, and dashboards.
Handles many requests efficiently, making it ideal for high-traffic
6️ Scalability
apps.
7️⃣ Improved Resource Servers can process multiple requests simultaneously, improving
Utilization speed.
Ans.
C.E., LDCE 44
220280107008 BHAYALA ABDULREHMAN
Ans. AJAX (Asynchronous JavaScript and XML) is a technique that allows web pages to update
without reloading by sending and receiving data asynchronously from a server in the background.
AJAX works by using the XMLHttpRequest object (or Fetch API) to send and receive data from a web
server asynchronously.
Ans.
Advantage Explanation
Only updates specific parts of a page instead of reloading the entire
1️ Faster Page Load
page.
2️ Improved User Experience Provides smooth interactions (e.g., live search, auto-suggestions).
3️ Reduced Server Load Sends and retrieves only necessary data, saving bandwidth.
4️ Asynchronous Processing Fetches data in the background while users interact with the page.
5️ Dynamic Content Updates Enables real-time features like notifications, chat, and live updates.
C.E., LDCE 45
BHAYALA ABDULREHMAN
220280107008
Advantage Explanation
6️ Better Performance Reduces unnecessary data transfer and speeds up responses.
7️ Cross-Browser Compatibility Works with modern browsers using XMLHttpRequest or fetch().
8️ Supports Multiple Data
Can handle JSON, XML, HTML, or plain text.
Formats
Ans. AJAX (Asynchronous JavaScript and XML) allows web applications to send and receive data from
a server without reloading the page. The two main ways to perform AJAX requests in JavaScript are:
The XMLHttpRequest object allows JavaScript to communicate with a server asynchronously. It was the
first method used for AJAX but has a complex syntax.
Q.9) What are the common status codes returned by AJAX requests, and what do they
signify?
Ans. When making an AJAX request using XMLHttpRequest or fetch(), the server responds with an
HTTP status code that indicates the success or failure of the request.
C.E., LDCE 46
BHAYALA ABDULREHMAN
220280107008
Q.10) What is jQuery and how does it simplify working with AJAX?
Ans. jQuery is a lightweight JavaScript library that simplifies HTML document traversal, event
handling, animations, and AJAX operations. It provides an easier way to interact with the DOM and make
AJAX requests with less code compared to vanilla JavaScript.
Instead of writing long XMLHttpRequest or fetch() code, jQuery provides a simple, cleaner syntax for
making AJAX requests.
Q.11) What is the difference between the $.get() and $.post() methods in jQuery?
Ans.
C.E., LDCE 47
220280107008 BHAYALA ABDULREHMAN
Q.12) What are the benefits of using jQuery for AJAX requests instead of using vanilla
JavaScript?
Ans.
Q.13) Explain the difference between synchronous and asynchronous behavior in jQuery's
AJAX functions.
Ans.
Q.14) What is a web service, and how does it differ from an API?
Ans. A web service is a network-based service that allows applications to communicate over the internet
using standard protocols like HTTP, SOAP, and REST.
C.E., LDCE 48
220280107008 BHAYALA ABDULREHMAN
Q.15) What is REST (Representational State Transfer), and how is it used in API
development?
Ans. REST is an architectural style used for building web services and APIs that follow a stateless, client-
server model. It defines a set of constraints that improve scalability, simplicity, and interoperability of web
services.
Q.16) Explain the basic HTTP methods (GET, POST, PUT, DELETE) used in RESTful API
development.
Response (JSON):
C.E., LDCE 49
220280107008 BHAYALA ABDULREHMAN
json
CopyEdit
[
{ "id": 1, "name": "John Doe", "email": "john@example.com" },
{ "id": 2, "name": "Jane Doe", "email": "jane@example.com" }
]
{
"name": "Alice",
"email": "alice@example.com"
}
Response:
{
"message": "User created successfully",
"id": 3
}
C.E., LDCE 50
220280107008 BHAYALA ABDULREHMAN
"email": "johnsmith@example.com"
}
Response:
{
"message": "User updated successfully"
}
Response:
{
"message": "User deleted successfully"
}
C.E., LDCE 51