Web Technology 2074-2080

Download as pdf or txt
Download as pdf or txt
You are on page 1of 34

2080

Group “A”

• Who makes Web standards?

• a. The World Wide Web Consortium


• b. World Wide Web
• c. Internet Society
• d. Web Programmer

a. The World Wide Web Consortium

• The text inside the <TEXTAREA> tag works like:

• a. <P> formatted text


• b. <T> formatted text
• c. <PRE> formatted text
• d. None of the above

c. <PRE> formatted text

• Which tag do we use to define the options present in the drop-down selection lists?

• a. <list>
• b. <option>
• c. <dropdown>
• d. <select>

b. <option>

• Which of the following is the correct syntax to link an external stylesheet in the HTML file?

• a. <link rel="stylesheet" href="style.css" />


• b. <link rel="stylesheet" src="style.css" />
• c. <style rel="stylesheet" src="style.css" />
• d. <style="stylesheet" link="style.css" />

a. <link rel="stylesheet" href="style.css" />

• Which is the correct way to write a JavaScript array?

• a. var city = new Array(1: "Kathmandu", 2: "Pokhara", 3:


"Butwal");
• b. var city = new Array: 1=("Kathmandu"), 2=("Pokhara"),
3=("Butwal");
• c. var city = new Array("Kathmandu", "Pokhara", "Butwal");
• d. var city = new Array = "Kathmandu", "Pokhara", "Butwal";

c. var city = new Array("Kathmandu", "Pokhara", "Butwal");

• Which function displays the information about PHP?

• a. sysinfo()
• b. phpinfo()
• c. info()
• d. php_info()

b. phpinfo()

• Which of the methods are used to manage result sets using both associative and indexed
arrays?

• a. get_array() and get_row()


• b. get_array() and get_column()
• c. fetch_array() and fetch_row()
• d. mysqli_fetch_array() and mysqli_fetch_row()

d. mysqli_fetch_array() and mysqli_fetch_row()

• Which of the following is the method that web servers use to host more than one domain name
on the same computer and IP address?

• a. WebHost
• b. Domain Name
• c. Virtual hosting
• d. MultiHosting

c. Virtual hosting

• What is the default value of max_execution_time directive? This directive specifies how
many seconds a script can execute before being terminated.

• a. 10
• b. 20
• c. 30
• d. 40

c. 30

• Which command is used to change the definition of a table in SQL?


• a. CREATE
• b. UPDATE
• c. SELECT
• d. ALTER

d. ALTER

Group ”B”

1. Define HTML lists? Explain different types of lists with examples.

HTML Lists: HTML lists are used to group a set of related items in a well-structured and
semantic way. There are three main types of lists in HTML: ordered lists, unordered lists, and
definition lists.

Types of HTML Lists:

1. Ordered List (<ol>): An ordered list is used when the order of the items matters. Each
item in the list is numbered.

Example:
<ol>
<li>First item</li>
<li>Second item</li>
<li>Third item</li>
</ol>

2. Unordered List (<ul>): An unordered list is used when the order of the items does not
matter. Each item in the list is marked with a bullet point.

Example:
<ul>
<li>First item</li>
<li>Second item</li>
<li>Third item</li>
</ul>

3. Definition List (<dl>): A definition list is used for items that come in pairs, like terms
and definitions.

Example:
<dl>
<dt>HTML</dt>
<dd>HyperText Markup Language</dd>
<dt>CSS</dt>
<dd>Cascading Style Sheets</dd>
<dt>JavaScript</dt>
<dd>A programming language for the web</dd>
</dl>

2. Define Cascading Style Sheet. What are the advantages of using CSS in web
development?

Cascading Style Sheet (CSS): CSS is a language used to describe the presentation of a
document written in HTML or XML. It controls the layout of multiple web pages all at once and
is a cornerstone technology of the World Wide Web, alongside HTML and JavaScript.

Advantages of using CSS in web development:

1. Separation of Content and Design:


o CSS allows you to separate the content (HTML) from the design (CSS), making
the code cleaner and easier to maintain.
2. Improved Website Speed:
o CSS reduces the size of the HTML file and makes it load faster. Stylesheets can
be cached by the browser, which reduces page load time.
3. Consistency in Design:
o CSS allows you to apply consistent styles across multiple web pages. This ensures
a uniform look and feel throughout the website.
4. Reusability:
o CSS styles can be reused across multiple HTML files, reducing redundancy and
effort.
5. Accessibility:
o CSS makes websites more accessible to different devices and screen sizes,
supporting responsive design.

OR

What do you mean by CSS layout? Explain different types of CSS layouts with examples.

CSS Layout: CSS layout refers to the arrangement of elements on a web page using CSS. It
determines how elements are displayed and positioned in relation to each other.

Different Types of CSS Layouts:

1. Normal Flow:
o The default layout where elements are displayed one after the other in the order
they appear in the HTML.
<div>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
</div>
2. Float Layout:
o Uses the float property to push elements to the left or right, allowing other
elements to wrap around them.
<div style="float: left; width: 50%;">
<p>This is a floated element.</p>
</div>
<div style="float: right; width: 50%;">
<p>This is another floated element.</p>
</div>

3. Flexbox Layout:
o A layout model that allows you to design a flexible and responsive layout
structure without using float or positioning.
<div style="display: flex;">
<div style="flex: 1;">Item 1</div>
<div style="flex: 1;">Item 2</div>
<div style="flex: 1;">Item 3</div>
</div>

4. Grid Layout:
o A two-dimensional layout system that allows you to create grid-based layouts
using rows and columns.
<div style="display: grid; grid-template-columns: auto auto
auto;">
<div>Item 1</div>
<div>Item 2</div>
<div>Item 3</div>
</div>

3. What are the features of JavaScript? Write a JavaScript code to find the factorial of a
user input number.

Features of JavaScript:

1. Lightweight and Interpreted:


o JavaScript is a lightweight, interpreted language that runs directly in the browser
without the need for compilation.
2. Dynamic Typing:
o Variables in JavaScript can hold values of any data type and can change types
dynamically.
3. Object-Oriented:
o JavaScript supports object-oriented programming concepts such as objects,
classes (introduced in ES6), inheritance, and more.
4. Event-Driven:
o JavaScript is designed to handle events such as user interactions (clicks, hovers,
etc.) and browser events (load, unload, etc.).
5. Functions as First-Class Citizens:
o Functions in JavaScript can be assigned to variables, passed as arguments to other
functions, and returned from functions.

JavaScript code to find the factorial of a user input number:


<!DOCTYPE html>
<html>
<head>
<title>Factorial Calculation</title>
</head>
<body>
<h1>Factorial Calculator</h1>
<input type="number" id="number" placeholder="Enter a
number">
<button onclick="calculateFactorial()">Calculate
Factorial</button>
<p id="result"></p>

<script>
function calculateFactorial() {
var num =
parseInt(document.getElementById('number').value);
var factorial = 1;

for (var i = 1; i <= num; i++) {


factorial *= i;
}

document.getElementById('result').innerText =
"Factorial of " + num + " is " + factorial;
}
</script>
</body>
</html>

4. What is string in PHP? Explain any five string functions with syntax and examples.

String in PHP: A string in PHP is a sequence of characters. It can be any text inside quotes. You
can use single or double quotes to define a string.

Five String Functions in PHP:

1. strlen():
o Returns the length of a string.
o Syntax: strlen(string)
o Example:
$str = "Hello, World!";
echo strlen($str); // Output: 13
2. strpos():
o Finds the position of the first occurrence of a substring in a string.
o Syntax: strpos(haystack, needle)
o Example:
$str = "Hello, World!";
echo strpos($str, "World"); // Output: 7

3. str_replace():
o Replaces all occurrences of a search string with a replacement string.
o Syntax: str_replace(search, replace, subject)
o Example:
$str = "Hello, World!";
echo str_replace("World", "PHP", $str); // Output:
Hello, PHP!

4. substr():
o Returns a part of a string.
o Syntax: substr(string, start, length)
o Example:
$str = "Hello, World!";
echo substr($str, 7, 5); // Output: World

5. strtoupper():
o Converts a string to uppercase.
o Syntax: strtoupper(string)
o Example:
$str = "Hello, World!";
echo strtoupper($str); // Output: HELLO, WORLD!

OR

Define session. Explain how to register, unregister and delete session Variable in PHP with
example.

Session:

A session in PHP is a way to store information (in variables) to be used across multiple pages.
Unlike cookies, the information is not stored on the user's computer.

Register, Unregister, and Delete Session Variables in PHP:

1. Registering a Session Variable:


<?php
session_start(); // Start the session
$_SESSION['username'] = 'JohnDoe'; // Register session
variable
?>

2. Unregistering (Unsetting) a Session Variable:


<?php
session_start(); // Start the session
unset($_SESSION['username']); // Unset session variable
?>

3. Deleting a Session:
<?php
session_start(); // Start the session
session_unset(); // Unset all session variables
session_destroy(); // Destroy the session
?>

5. Explain the use of $_GET and $_POST methods in form submitting with proper
example with their differences.

$_GET Method:

• Purpose: Used to send data to the server as URL parameters.


• Security: Less secure because data is visible in the URL.
• Usage: Suitable for non-sensitive data, like search queries or fetching public information.
• Example:
<form action="process.php" method="get">
<label for="name">Name:</label>
<input type="text" id="name" name="name">
<button type="submit">Submit</button>
</form>

When the form is submitted, the URL will look like: process.php?name=John

$_POST Method:

• Purpose: Used to send data to the server in the body of the HTTP request.
• Security: More secure because data is not visible in the URL.
• Usage: Suitable for sensitive data, like passwords or personal information.
• Example:
<form action="process.php" method="post">
<label for="password">Password:</label>
<input type="password" id="password" name="password">
<button type="submit">Submit</button>
</form>

Data sent through POST is not visible in the URL.

Differences:
• Visibility: $_GET appends form data to the URL, making it visible and bookmarkable.
$_POST does not modify the URL.
• Security: $_POST is more secure as it doesn't expose sensitive data in the URL.
• Data Size: $_GET has limits on the amount of data it can handle (URL length
limitations), while $_POST can handle larger amounts of data.

6. What is mysql_fetch_array()? Explain how to retrieve data from the MySQL database
using PHP.

mysql_fetch_array():

• mysql_fetch_array() is a PHP function used to fetch a result row from a MySQL


database query as an associative array, a numeric array, or both.

Example: Suppose you have a MySQL database students with a table student_info
containing fields id, name, and age. Here's how you can retrieve data using PHP:

1. Connecting to MySQL:
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "students";

// Create connection
$conn = new mysqli($servername, $username, $password,
$dbname);

// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
?>

2. Executing Query and Retrieving Data:


<?php
// SQL query
$sql = "SELECT id, name, age FROM student_info";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
// Output data of each row
while($row = $result->fetch_array()) {
// Access data using both associative and numeric
indices
echo "ID: " . $row["id"]. " - Name: " .
$row["name"]. " - Age: " . $row["age"]. "<br>";
// Alternatively, you can use numeric indices:
$row[0], $row[1], etc.
}
} else {
echo "0 results";
}
$conn->close();
?>

Explanation:

• mysqli_fetch_array($result, $resulttype): Fetches a row from the result set returned by


mysqli_query(). By default, it returns both associative and numeric arrays
(MYSQLI_BOTH), but you can specify MYSQLI_ASSOC for associative arrays or
MYSQLI_NUM for numeric arrays.
• Steps:
o Establish a connection to the MySQL database using mysqli_connect().
o Execute an SQL query using mysqli_query().
o Use mysqli_fetch_array() to fetch rows from the result set, iterate
through them using a loop (like while), and access the fetched data.

This approach retrieves data from the MySQL database students, displaying student IDs,
names, and ages. Adjustments can be made based on specific table structures and query
requirements.

2079

1. Describe the <img> and <a> tag with an example.

<img> Tag: The <img> tag is used to embed images in an HTML page. It is an empty tag,
meaning it doesn't have a closing tag. It requires the src attribute, which contains the path to the
image, and the alt attribute, which provides alternative text for the image.

Example:
<img src="image.jpg" alt="A beautiful scenery">

<a> Tag: The <a> tag defines a hyperlink, which is used to link from one page to another. The
most important attribute of the <a> element is the href attribute, which indicates the link's
destination.

Example:
html
Copy code
<a href="https://www.example.com">Visit Example.com</a>
2. How is HTML different from CSS? Explain the ways for inserting CSS code into an
HTML file.

HTML (HyperText Markup Language):

• HTML is used for creating the structure of web pages.


• It uses tags to create elements such as headings, paragraphs, images, links, etc.

CSS (Cascading Style Sheets):

• CSS is used for styling and designing web pages.


• It defines how HTML elements are to be displayed.

Ways to insert CSS into an HTML file:

1. Inline CSS: Directly within an HTML element using the style attribute.
<p style="color:blue;">This is a blue paragraph.</p>

2. Internal CSS: Within a <style> tag inside the <head> section of an HTML
document.
<head>
<style>
p {
color: blue;
}
</style>
</head>

3. External CSS: Using an external CSS file linked to the HTML document.
<head>
<link rel="stylesheet" href="styles.css">
</head>

OR

What is media query? Explain how to create a responsive web page with example.

Media Query: A media query is a CSS technique used to apply styles based on the conditions
like screen size, resolution, and orientation. It helps in creating responsive web designs that look
good on various devices.

Example of Media Query:


@media (max-width: 600px) {
body {
background-color: lightblue;
}
}

Creating a Responsive Web Page:


<!DOCTYPE html>
<html>
<head>
<title>Responsive Web Page</title>
<style>
body {
font-family: Arial, sans-serif;
}
.container {
width: 100%;
padding: 20px;
background-color: lightgrey;
}
@media (max-width: 600px) {
.container {
background-color: lightblue;
}
}
</style>
</head>
<body>
<div class="container">
<h1>Responsive Design Example</h1>
<p>This container changes color based on screen
width.</p>
</div>
</body>
</html>

3. Create an HTML form for student information to enter marks in five subjects and write
a JavaScript code to find total, average, result, and grade.

HTML Form:
<!DOCTYPE html>
<html>
<head>
<title>Student Information Form</title>
</head>
<body>
<form id="studentForm">
<label for="subject1">Subject 1:</label>
<input type="number" id="subject1" name="subject1"><br>

<label for="subject2">Subject 2:</label>


<input type="number" id="subject2" name="subject2"><br>

<label for="subject3">Subject 3:</label>


<input type="number" id="subject3" name="subject3"><br>

<label for="subject4">Subject 4:</label>


<input type="number" id="subject4" name="subject4"><br>

<label for="subject5">Subject 5:</label>


<input type="number" id="subject5" name="subject5"><br>

<input type="button" value="Calculate"


onclick="calculateResults()">
</form>

<p id="results"></p>

<script>
function calculateResults() {
var subject1 =
parseFloat(document.getElementById('subject1').value);
var subject2 =
parseFloat(document.getElementById('subject2').value);
var subject3 =
parseFloat(document.getElementById('subject3').value);
var subject4 =
parseFloat(document.getElementById('subject4').value);
var subject5 =
parseFloat(document.getElementById('subject5').value);

var total = subject1 + subject2 + subject3 +


subject4 + subject5;
var average = total / 5;
var result = (subject1 >= 40 && subject2 >= 40 &&
subject3 >= 40 && subject4 >= 40 && subject5 >= 40) ? "Pass" :
"Fail";
var grade;

if (average >= 90) {


grade = "A+";
} else if (average >= 80) {
grade = "A";
} else if (average >= 70) {
grade = "B+";
} else if (average >= 60) {
grade = "B";
} else if (average >= 50) {
grade = "C+";
} else if (average >= 40) {
grade = "C";
} else {
grade = "F";
}

document.getElementById('results').innerHTML =
"Total: " + total + "<br>Average: " + average + "<br>Result: " +
result + "<br>Grade: " + grade;
}
</script>
</body>
</html>

4. What are the advantages and disadvantages of using CSV file format? Explain how to
display data from a CSV file using PHP.

Advantages of CSV:

• Simple to understand and create.


• Compatible with most applications (e.g., Excel, Google Sheets).
• Easy to parse and generate programmatically.

Disadvantages of CSV:

• Limited to textual data, no support for complex data types.


• No standard way to handle metadata or nested data structures.
• Can be error-prone with delimiters if data contains commas.

Display data from a CSV file using PHP:


<?php
// Open the CSV file
$file = fopen('data.csv', 'r');

// Read the file line by line


echo "<table border='1'>";
while (($line = fgetcsv($file)) !== FALSE) {
echo "<tr>";
foreach ($line as $cell) {
echo "<td>" . htmlspecialchars($cell) . "</td>";
}
echo "</tr>";
}
echo "</table>";

// Close the file


fclose($file);
?>

OR

Define array. Explain about the types of Arrays in PHP with examples.

Array: An array is a special variable that can hold multiple values at once.

Types of Arrays in PHP:

1. Indexed Arrays: Arrays with a numeric index.


$fruits = array("Apple", "Banana", "Cherry");
echo $fruits[1]; // Output: Banana

2. Associative Arrays: Arrays with named keys.


$age = array("Peter" => 35, "Ben" => 37, "Joe" => 43);
echo $age['Ben']; // Output: 37

3. Multidimensional Arrays: Arrays containing one or more arrays.


$cars = array(
array("Volvo", 22, 18),
array("BMW", 15, 13),
array("Saab", 5, 2),
array("Land Rover", 17, 15)
);
echo $cars[0][0]; // Output: Volvo
echo $cars[0][1]; // Output: 22

5. Differentiate mysql_fetch_row() and mysql_fetch_array() function.

• mysql_fetch_row(): Fetches one row of data from the result set as a numeric array.
$row = mysql_fetch_row($result);
echo $row[0]; // Accesses the first column of the fetched
row

• mysql_fetch_array(): Fetches one row of data from the result set as an associative
array, a numeric array, or both. It is more versatile.
$row = mysql_fetch_array($result);
echo $row['column_name']; // Accesses the data by column
name
echo $row[0]; // Accesses the data by column index

6. How PHP and MySQL are related? Explain how to execute MySQL "insert and select"
query and fetch results stu_roll, stu_name, stu_address from database table
"students" using PHP.
PHP and MySQL Relationship:

• PHP is a server-side scripting language commonly used to interact with databases.


• MySQL is a popular database management system used with PHP for dynamic web
development.

Executing MySQL Insert and Select Queries:

Insert Query:
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

// Insert query
$sql = "INSERT INTO students (stu_roll, stu_name, stu_address)
VALUES (1, 'John Doe', '123 Main St')";

if ($conn->query($sql) === TRUE) {


echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();
?>

Select Query:
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

// Select query
$sql = "SELECT stu_roll, stu_name, stu_address FROM students";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
// Output data of each row
while($row = $result->fetch_assoc()) {
echo "Roll: " . $row["stu_roll"]. " - Name: " .
$row["stu_name"]. " - Address: " . $row["stu_address"]. "<br>";
}
} else {
echo "0 results";
}

$conn->close();
?>
Group "A"

1. How can you create an email link?

a. <a href= "abc@xyz" >

b. <mail href= "abc@xyz" >

c. <mail> abc@xyz </mail>

d. <a href="mailto:abc@xyz">

2. Which of the following is used to specify the superscript of text using CSS?

a. vertical-align: super

b. vertical-align: baseline

c. vertical-align: superscript

d. none of the above

a. vertical-align: super

3. Which of the following specifies the "Green" color with opacity?


a. rgba (0, 255, 0, 255)

b. rgba (255, 255, 255, 0.5)

c. rgba (0, 255, 0, 0.5)

d. rgba (255, 0, 255, 0.5)

c. rgba (0, 255, 0, 0.5)

4. What does the 'alt' attribute do?

a. used to distinguish image and text links by a screen reader

b. describes the information the image conveys or its function

c. display information about an ambiguous image as a tooltip

d. links to a URL

b. describes the information the image conveys or its function

5. Which of the following is a client-side JavaScript object?

a. Function

b. File

c. Date

d. Window

d. Window

6. Another name given to a CSV file is

a. 3D file

b. Flat file

c. String file

d. Random file

b. Flat file
7. What is name of PHP "===" operator?

a. Equal

b. Identical

c. Identity

d. Safe Equal

b. Identical

8. Which of the following is not a Built-in String functions in PHP?

a. strlen()

b. str_replace()

c. strpos()

d. strreverse()

d. strreverse()

9. Which method returns the error code generated from the execution of the last MySQL
function?

a. errno()

b. errnumber()

c. errorno()

d. errornumber()

a. errno()

10. Which of the following command is used to delete all rows and free up space from a
table?

a. TRUNCATE

b. DROP

c. DELETE
d. ALTER

a. TRUNCATE
2078
Group "A"
This tag defines a section in an HTML document:
(a) div
Which attribute can be added to many HTML elements to identify them as a member of a
specific group?
(a) id
Study the following steps and determine the correct order:

(b) 4, 2, 3, 5, 1
Open a connection to MySQL server
Execute the SQL query
Fetch the data from query
Select the database
Close the connection
Which HTML attribute is used to define inline styles?

(a) style
Which of the following is the correct syntax for adding a comment in CSS code?
(a) /* comment */
Which of the following variables takes precedence over the others if the names are the same?
(b) Local variable
In JavaScript, the === statement implies that:
(a) Both A and B are equal in value, and data types are also the same
PHP stands for:
(d) PHP Hypertext Preprocessor
Which one of the following sends input to a script via a URL?
(a) Get
Which one of the following functions is used to start a session?
(a) start_session()
1. What do you mean by responsive CSS? What are its advantages?
Responsive CSS refers to the use of CSS (Cascading Style Sheets) techniques to create web pages
that adapt to different screen sizes and devices. This ensures that the content is easily readable
and the layout is usable on any device, from desktop computers to tablets and smartphones.
Advantages:
Improved User Experience: Ensures a seamless experience across all devices, enhancing user
satisfaction.
Increased Mobile Traffic: With more people accessing the web via mobile devices, responsive
design can help capture and retain this audience.
Cost Effective: Reduces the need for separate mobile and desktop websites.
SEO Benefits: Google favors mobile-friendly websites in search rankings.
Easier Maintenance: One website to update, rather than multiple versions.
OR
What is sessions in PHP? How is it different from cookies?
Sessions in PHP are a way to store information (in variables) to be used across multiple pages.
Unlike cookies, the information is not stored on the user's computer. Sessions are used to
maintain state and user data across the site.
Differences between Sessions and Cookies:
Storage Location: Sessions store data on the server, while cookies store data on the client's
browser.
Security: Sessions are generally more secure as the data is stored on the server, reducing the
risk of user tampering.
Lifetime: Session data is temporary and typically expires when the user closes the browser,
while cookies can persist for a specified duration.
Data Size: Cookies have a size limit of around 4KB, whereas sessions can handle larger amounts
of data.
2. Write short notes on : AMP, Server side scripting language and Static website.
AMP (Accelerated Mobile Pages):
AMP is an open-source project designed to optimize web pages for mobile browsing by enabling
faster load times. It uses a stripped-down version of HTML and a limited set of JavaScript to
ensure high performance and speedy rendering on mobile devices.
Server Side Scripting Language:
A server-side scripting language is a programming language used to create dynamic web pages.
The script runs on the server rather than the user's browser. Examples include PHP, Python,
Ruby, and Node.js. These languages interact with databases, process form data, and generate
HTML content before sending it to the client's browser.

Static Website:
A static website consists of web pages with fixed content. Each page is an HTML file stored on a
server and sent to the user's browser as-is. Static websites do not require server-side processing
and are ideal for small websites with infrequent content changes. They are fast, secure, and
easy to host.

3. What do you mean by event handler in JavaScript? Write script to show it.
An event handler in JavaScript is a function that executes in response to a specific event
triggered by user interaction or browser actions (e.g., clicks, form submissions, page loads).

Example Script:
<!DOCTYPE html>
<html>
<head>
<title>Event Handler Example</title>
<script type="text/javascript">
function handleClick() {
alert('Button clicked!');
}
</script>
</head>
<body>
<button onclick="handleClick()">Click Me!</button>
</body>
</html>
4. Write about scope of variable in PHP. How can you pass value by reference in function?
Give example.
Scope of Variable in PHP:
The scope of a variable in PHP determines where it can be accessed or modified. The main
scopes are:

Local Scope: Variables declared within a function are only accessible within that function.
Global Scope: Variables declared outside any function are accessible globally, but not within
functions unless explicitly stated.
Static Scope: Static variables retain their value even after the function has exited.
Pass by Reference:
Passing by reference means passing the actual memory address of the variable, allowing the
function to modify the variable's value.

Example:
<?php
function addFive(&$number) {
$number += 5;
}

$value = 10;
addFive($value);
echo $value; // Outputs: 15
?>
5. Differentiate between GET and POST.
GET:
Data in URL: Appends data to the URL.
Size Limit: Limited by URL length (about 2048 characters).
Security: Less secure as data is exposed in the URL.
Caching: Data can be cached and bookmarked.
Usage: Suitable for non-sensitive data and query strings.
POST:
Data in Body: Sends data in the request body.
Size Limit: No significant size limit.
Security: More secure as data is not exposed in the URL.
Caching: Data is not cached or bookmarked.
Usage: Suitable for sensitive data and form submissions.
6. Write about any three database functions of PHP with syntax.
mysqli_connect():
Description: Establishes a new connection to the MySQL database.
Syntax:
$conn = mysqli_connect($servername, $username, $password, $dbname);
mysqli_query():
Description: Performs a query against the database.
Syntax:
$result = mysqli_query($conn, $sql);
mysqli_fetch_assoc():
Description: Fetches a result row as an associative array.
Syntax:
$row = mysqli_fetch_assoc($result);
OR
Write HTML code for:
mathematica
ABC
D E
F
HTML Code:
<!DOCTYPE html>
<html>
<head>
<title>Table Layout</title>
</head>
<body>
<table border="1">
<tr>
<td>A</td>
<td>B</td>
<td>C</td>
</tr>
<tr>
<td>D</td>
<td colspan="2"></td>
<td>E</td>
</tr>
<tr>
<td>F</td>
</tr>
</table>
</body>
</html>
2077
Group "A"
Which of the following is an invalid HTML Tag?
a. <sup>
b. <sub>
c. <pow>
d. <BR>
Answer: c. <pow>
Which of the following attributes of the text box allows to limit the maximum character?
a. Size
b. Max
c. Maxlength
d. Maxlen
Answer: c. Maxlength
If we want to wrap a block of text around an image, which CSS property will we use?
a. Wrap
b. Float
c. Push
d. Clear
Answer: b. Float
What is the correct HTML for referring to an external style sheet?
a. <stylesheet>mystyle.css</stylesheet>
b. <link rel="stylesheet" type="text/css" href="mystyle.css">
c. <style src="mystyle.css" />
d. <link external="stylesheet" type="text/css" href="mystyle.css">
Answer: b. <link rel="stylesheet" type="text/css" href="mystyle.css">
When a user views a page containing a JavaScript program, which machine actually executes
the script?
a. Web Server
b. Application Server
c. Central Server
d. Client
Answer: d. Client
What is the output for the script:
<script type="text/javascript"> x=4+"4"; document.write(x); </script>
a. 44
b. 4
c. 8
d. Error
Answer: a. 44
What should we need to do to turn formal parameter names into default arguments?
a. Use assignment expression
b. Use Boolean expression
c. Use values rather than parameters
d. None of them
Answer: a. Use assignment expression
Which of the following methods sends input to a script via a URL?

a. Post
b. Get
c. Both
d. Send
Answer: b. Get
Which of the following array represents an array with strings as index?
a. Numeric Array
b. Ragged Array
c. Associative Array
d. String Array
Answer: c. Associative Array
Which one of the following statements can be used to select the database?
a. $mysqli=select_db('databasename')
b. mysqli=select_db('databasename')
c. mysqli->select_db('databasename')
d. $mysqli->select_db('databasename')
Answer: d. $mysqli->select_db('databasename')
Group "B"
Discuss different types of HTML tags used for creating lists with suitable examples.
Answer:
Ordered List (<ol>):
<ol>
<li>Item 1</li>
<li>Item 2</li>
</ol>
Unordered List (<ul>):
<ul>
<li>Item 1</li>
<li>Item 2</li>
</ul>
Description List (<dl>):
<dl>
<dt>Term 1</dt>
<dd>Description 1</dd>
</dl>
How can you use ID and class selectors? Explain with examples.
Answer:
ID Selector:
<style>
#myId {
color: blue;
}
</style>
<div id="myId">This is a div with an ID.</div>
Class Selector:
<style>
.myClass {
color: red;
}
</style>
<div class="myClass">This is a div with a class.</div>
<p class="myClass">This is a paragraph with the same class.</p>
Create a form containing fields User ID, password and Cell Number and validate the form such
that none of the fields are empty, password must be of at least six digits and cell number
should only contain digits using JavaScript.

Answer:
<form id="myForm">
User ID: <input type="text" id="userId"><br>
Password: <input type="password" id="password"><br>
Cell Number: <input type="text" id="cellNumber"><br>
<input type="button" value="Submit" onclick="validateForm()">
</form>
<script>
function validateForm() {
var userId = document.getElementById("userId").value;
var password = document.getElementById("password").value;
var cellNumber = document.getElementById("cellNumber").value;
if (userId === "" || password === "" || cellNumber === "") {
alert("All fields are required.");
return false;
}
if (password.length < 6) {
alert("Password must be at least 6 characters long.");
return false;
}
if (!/^\d+$/.test(cellNumber)) {
alert("Cell number must contain only digits.");
return false;
}
alert("Form is valid.");
}
</script>
Explain the concept of pass by value and pass by reference with suitable PHP code.
Answer:
// Pass by value
function incrementByValue($num) {
$num += 1;
}
$a = 5;
incrementByValue($a);
echo $a; // Outputs: 5

// Pass by reference
function incrementByReference(&$num) {
$num += 1;
}
$b = 5;
incrementByReference($b);
echo $b; // Outputs: 6
What is session? How sessions can be handled in PHP? Explain with example.
Answer:
// Start the session
session_start();

// Set session variables


$_SESSION["username"] = "JohnDoe";
$_SESSION["email"] = "[email protected]";
// Access session variables
echo "Username: " . $_SESSION["username"]; // Outputs: JohnDoe
echo "Email: " . $_SESSION["email"]; // Outputs: [email protected]
// Destroy the session
session_destroy();
Write any three database functions of PHP with examples.
Answer:
// 1. Connect to MySQL database
$conn = mysqli_connect("localhost", "username", "password", "database");
// 2. Query the database
$result = mysqli_query($conn, "SELECT * FROM table");
// 3. Fetch data from the result set
while ($row = mysqli_fetch_assoc($result)) {
echo $row["column"];
}
Write down a PHP code snippet for selecting an Eid, Ename, and Salary from table
"Employee" and display them in a browse window.

Answer:
// Connect to the database
$conn = mysqli_connect("localhost", "username", "password", "database");
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}

// Query the database


$sql = "SELECT Eid, Ename, Salary FROM Employee";
$result = mysqli_query($conn, $sql);

// Check if there are results


if (mysqli_num_rows($result) > 0) {
// Output data of each row
while($row = mysqli_fetch_assoc($result)) {
echo "Eid: " . $row["Eid"]. " - Name: " . $row["Ename"]. " - Salary: " . $row["Salary"]. "<br>";
}
} else {
echo "0 results";
}

// Close connection
mysqli_close($conn);

2075
Group "B" - Short Answer Questions:
Describe the <Form> and <Table> tag with examples.
Form Tag:
<form action="/submit-form" method="post">
<label for="name">Name:</label>
<input type="text" id="name" name="name">
<input type="submit" value="Submit">
</form>
The <form> tag is used to create an HTML form for user input. The action attribute specifies
where to send the form data when a form is submitted. The method attribute specifies the
HTTP method (GET or POST) to be used when submitting the form.
Table Tag:
<table>
<tr>
<th>Header 1</th>
<th>Header 2</th>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
</tr>
</table>
The <table> tag is used to create a table in HTML. <tr> defines a row in the table, <th> defines a
header cell, and <td> defines a standard data cell.
What is CSS? Describe the CSS layout techniques.
CSS (Cascading Style Sheets): CSS is a language used to describe the presentation of a document
written in HTML or XML. It controls the layout, colors, fonts, and overall visual appearance of
web pages.
CSS Layout Techniques:
Flexbox: A one-dimensional layout method for arranging items in rows or columns.
Grid: A two-dimensional layout system for designing web pages.
Float: An older method used to position elements to the left or right within a container.
Positioning: Using properties like absolute, relative, fixed, and sticky to control the placement of
elements.
Box Model: Understanding and manipulating the margin, border, padding, and content of
elements.
Write a JavaScript to validate the form at client side where student roll number, sex, and email
fields are not accepted in blank.

function validateForm() {
var rollNumber = document.forms["studentForm"]["rollNumber"].value;
var sex = document.forms["studentForm"]["sex"].value;
var email = document.forms["studentForm"]["email"].value;

if (rollNumber == "" || sex == "" || email == "") {


alert("All fields must be filled out");
return false;
}
return true;
}
What is a web server? Write configuration process of Apache server in Windows operating
system.
Web Server: A web server is a software that serves web pages to users upon request. It handles
HTTP requests from clients (browsers) and responds with HTML pages or other content.
Apache Server Configuration in Windows:
Download and Install Apache: Download the Apache HTTP Server from its official website and
run the installer.
Edit the httpd.conf File: This file is typically located in the conf directory of your Apache
installation. Modify settings like the ServerRoot, DocumentRoot, and Listen directives as
needed.
Start the Apache Service: Use the Apache Monitor or the command prompt (httpd.exe or
apache.exe) to start the Apache service.
Test the Server: Open a web browser and navigate to http://localhost. If Apache is configured
correctly, you should see the default Apache welcome page.
What is a function? How do you implement the function in PHP by passing argument? Explain
with example.

Function: A function is a block of code that performs a specific task. It is defined once and can
be executed whenever called.
PHP Function Example:
function greet($name) {
return "Hello, " . $name;
}

echo greet("John");
This PHP function greet takes one argument $name and returns a greeting message.
What is MySQL? Describe the database connection methods in PHP.
MySQL: MySQL is an open-source relational database management system (RDBMS) based on
SQL (Structured Query Language).
PHP Database Connection Methods:
MySQLi (MySQL Improved):
$conn = new mysqli("localhost", "username", "password", "database");
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
PDO (PHP Data Objects):
php
Copy code
try {
$conn = new PDO("mysql:host=localhost;dbname=database", "username", "password");
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
echo "Connection failed: " . $e->getMessage();
}
Group "A" - Multiple Choice Questions:
What is the correct HTML for inserting an image?
c. <img src="image.gif" alt="My Image">
Which method is ideal for applying the same style to an entire website?
c. External CSS
Which of the following is correct to write "Hello World" on the web page?
c. document.write("Hello World")
Which of the following syntax is correct to refer an external script called "form Validation.js"?
a. <script href="form Validation.js">
What is the default extension for Apache configuration files?
a. .con
Which symbol is used to start with all variables in PHP?
a. $
Which of the following is an associative array containing session variables available to the
current script?
c. $_SESSION
Which one of the following statements can be used to select the database?
a. mysqli_select_db('databasename');
Which function is used to determine whether a file was uploaded?
a. is_file_uploaded()
Which statement is true for retrieving data from a FORM with an input named 'distance' that
is submitted using the "post" method?
a. $gap=$_POST['distance'];
2074
Group "B" - Short Answer Questions:
Describe the <IMG> and <A> tag with example.
IMG Tag:
<img src="image.jpg" alt="Sample Image">
The <img> tag is used to embed images in HTML. The src attribute specifies the path to the
image, and the alt attribute provides alternative text for the image.
A Tag:
<a href="https://www.example.com">Visit Example</a>
The <a> tag is used to create hyperlinks. The href attribute specifies the URL of the page the link
goes to.
What are the different types of CSS used in webpage designing? Explain.
Inline CSS:
<p style="color:blue;">This is a blue paragraph.</p>
CSS styles are applied directly within an HTML element using the style attribute.
Internal CSS:
<head>
<style>
p { color: blue; }
</style>
</head>
CSS rules are defined within the <style> tag inside the <head> section of the HTML document.
External CSS:
<head>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
CSS rules are placed in an external file, which is linked to the HTML document using the <link>
tag.
Why do you use JavaScript? Write a JavaScript program to calculate multiplication and
division of two numbers provided by users.
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Multiplication and Division</h2>
<input type="number" id="num1" placeholder="Enter first number">
<input type="number" id="num2" placeholder="Enter second number">
<button onclick="calculate()">Calculate</button>
<p id="result"></p>

<script>
function calculate() {
var num1 = document.getElementById('num1').value;
var num2 = document.getElementById('num2').value;
var multiplication = num1 * num2;
var division = num1 / num2;
document.getElementById('result').innerHTML = "Multiplication: " + multiplication +
"<br>Division: " + division;
}
</script>
</body>
</html>
Explain about Web Server? What are the major issues in httpd.conf file to troubleshoot web
server in Apache?

Web Server: A web server is software that serves web pages to clients upon request. It
processes incoming network requests over HTTP and several other related protocols.

Major Issues in httpd.conf File:

Syntax Errors: Incorrect syntax can prevent Apache from starting.


Incorrect DocumentRoot: Setting the wrong document root can lead to "file not found" errors.
Port Conflicts: The Listen directive should specify a port not used by other services.
Module Issues: Modules specified with LoadModule should be correctly installed and
referenced.
Permission Issues: Directories and files specified should have appropriate read/write
permissions.
What are the different types of loops used in PHP? Explain the "FOR" loop with example.
Types of Loops:
for loop
while loop
do-while loop
foreach loop
FOR Loop Example:
<?php
for ($x = 0; $x <= 10; $x++) {
echo "The number is: $x <br>";
}
?>
The for loop executes a block of code a specified number of times. It consists of three parts:
initialization, condition, and increment/decrement.
Describe the database connection process in PHP.
Database Connection Using MySQLi:
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
Database Connection Using PDO:
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";

try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected successfully";
} catch(PDOException $e) {
echo "Connection failed: " . $e->getMessage();
}
?>
Group "A" - Multiple Choice Questions:
How can you open a link in a new browser window?
c. <a href="url" target="_new">
What form of style rules are presented in CSS?
a. selector {property : value}
Which of the following is the correct way for writing JavaScript array?
b. var salaries = new Array(1:39438, 2:39839, 3:83729)
Which of the tag is an extension to HTML that can enclose any number of JavaScript
statements?
a. <SCRIPT>
Where is the default location for the main Apache configuration file (httpd.conf) on
Windows?
a. C:\Program Files\Apache Software Foundation\Apache2.2\conf
Which of the following will start a session in PHP?
a. session_start();
How do you get information from a form that is submitted using the "get" method?
a. $_GET[]
What is the best all-purpose way of comparing two strings?
a. Using the strcmp function
Which directive determines whether PHP scripts on the server can accept file uploads?
a. file_uploads
Which of the following parameter is not taken by mysql_connect() function in PHP?
c. User ID

You might also like