Web Programming-Questionbank solved
Web Programming-Questionbank solved
1. Construct a valid HTML document for your personal Profile registration page for a Job
Site www.123Jobs.com. Add relevant HTML elements in a table, to accept a minimum of 10
different fields which includes your name, address, phone, email address, your picture, your
college; your branch, fields for your personal history (Minimum 3 fields), favourite theory
and practical subjects (Checkbox), Username, Password(password).
Ans. MIME (Multipurpose Internet Mail Extensions) is a standard that extends the format of
email messages to support text in character sets other than ASCII, as well as attachments of
audio, video, images, and application programs. MIME types are used to specify the format
of a file in the HTTP protocol used by the World Wide Web. This is done via the "Content-
Type" header in the HTTP request and response.
3. What is codec? Recognize the role of controls attribute in <video> & <audio> tag in HTML.
Use the COVID vaccination promotional video ‘MySafety.mp4’ in a web page with suitable
HTML code, ‘auto play’ option enabled and displayed in a standard dimension 750 X500.
Ans. A codec is a device or software that compresses and decompresses digital media, such
as audio and video files. Codecs are used to reduce the size of large media files, making them
more manageable for storage and transmission over networks.
The controls attribute in the <video> and <audio> tags in HTML is used to enable the default
set of controls for the media player, such as play/pause, volume, and seek controls.
<!DOCTYPE html>
<html>
<head>
<title>COVID Vaccination Promotional Video</title>
This code will embed the video "MySafety.mp4" on the webpage. The auto play attribute is
set on the <video> tag which will automatically start playing the video when the page loads.
The width and height attributes set the dimension of the video to 750x500 pixels. The controls
attribute is set on the <video> tag which will enable the default set of controls for the media
player. It is worth noting that the auto play feature can be blocked by some browsers and
devices and also, it's not recommended to use it as it could cause an annoying experience for
the user, and also it could use a lot of data and battery. It's always best to give the user the
option to start the video.
1. Organize a sample web page for the event ‘Raagam2021’ at your campus and use
embedded Style sheets to apply a minimum 5 styles. State the Style Specification
format of embedded style sheets.
The style specification format of embedded style sheets in HTML is CSS (Cascading Style
Sheets). CSS is a stylesheet language used to describe the presentation of a document written
in a markup language. It is most commonly used to style HTML and XHTML documents, but
can also be applied to other types of documents, such as XML. In an embedded style sheet,
CSS styles are added directly to the HTML document using the <style> tag, which should be
placed in the <head> of the HTML document. The styles are then applied to the elements in
the HTML document according to the selectors, properties, and values specified in the CSS
styles.
selector {
property: value;
}
For example:
body {
background-color: #F5F5DC;
Ans. Here are the CSS style rules to implement the following in a web page:
a. To display the content of hyperlinks with yellow background colour and in italics:
a{
background-color: yellow;
font-style: italic;
}
ul {
font-weight: bold;
font-family: Arial;
}
body {
background-image: url("birds.jpg");
background-repeat: no-repeat;
}
3. Write the code for an HTML document with embedded JavaScript scripts, which initially
displays a paragraph with text "Welcome" and a button titled "Click". When the button is
clicked, the message "Hello from JavaScript" in bold should replace the paragraph text.
1. Write a PHP program to store the name and roll no of 10 students in an Associative Array
and Use foreach loop to process the array and Perform asort, rsort and ksort in the array.
Illustrate with suitable output data
Ans. <?php
// Creating an associative array to store name and roll no of 10 students
$students = array(
array("name" => "John", "roll" => 1),
array("name" => "Mike", "roll" => 2),
array("name" => "Sara", "roll" => 3),
array("name" => "Mark", "roll" => 4),
array("name" => "Julia", "roll" => 5),
array("name" => "Laura", "roll" => 6),
array("name" => "David", "roll" => 7),
array("name" => "Emily", "roll" => 8),
array("name" => "Adam", "roll" => 9),
array("name" => "Amy", "roll" => 10)
);
2. Design an HTML page which enters a given number, write a PHP program to display a
message indicating, whether the number is odd or even, when clicking on the submit
button.
<!DOCTYPE html>
<html>
<head>
<title>Odd or Even</title>
</head>
<body>
<form action="submit.php" method="post">
Enter a number: <input type="text" name="num"><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
PHP program to display a message indicating, whether the number is odd or even:
<?php
if(isset($_POST['num'])) {
$num = $_POST['num'];
if($num % 2 == 0) {
echo "The number is even";
} else {
echo "The number is odd";
In this HTML page, there is a form with a single text input field for a number and a submit
button. When the user enters a number and clicks the submit button, the form data is sent to
the PHP script "submit.php" which receives the entered number and checks if it is odd or even
using the modulus operator and prints the message accordingly.
3. Write a PHP program to compute the sum of the positive integers up to 100 using do
While.
Ans. <?php
$sum = 0;
$i = 1;
do {
$sum += $i;
$i++;
} while ($i <= 100);
echo "The sum of positive integers up to 100 is: $sum";
?>
In this case, the output will be the sum of positive integers up to 100 is: 5050
In this PHP program, a variable $sum is initialized with 0, and a variable $i is initialized with 1.
The do-while loop runs until the condition $i <= 100 is true. In each iteration of the loop, the
value of $i is added to the $sum variable and $i is incremented by 1. After the loop has finished
executing, the final value of $sum variable will be the sum of all positive integers up to 100.
1. Write a PHP form handling program to verify the user authentication credentials of a web
page using MySQL connection and store the user id value as a Session variable if the user id
is valid.
Ans. <?php
session_start(); // Starting a session
// Connect to MySQL
$con = mysqli_connect("hostname", "username", "password", "database_name");
if(!$con) {
<form method="post">
User ID: <input type="text" name="userid"><br>
Password: <input type="password" name="password"><br>
<input type="submit" name="submit" value="Submit">
</form>
This PHP program uses the session_start() function to start a session, then connects to a
MySQL database using the mysqli_connect() function. The program checks if the form has
been submitted using the isset($_POST['submit']) condition. If the form has been submitted,
the program retrieves the userid and password values from the $_POST array, and uses them
to query the users table in the MySQL database. If the query returns any rows, it means the
userid and password are valid, so the userid is stored in a session variable using the $_SESSION
array and the user is redirected to the protected_page.php. If the query returns no rows, it
means the userid and password are invalid, so an error message is displayed.
2. Create a valid HTML document for yourself, including your name, address, and email
address. Also add your college; your major and the course. Perform form handling in PHP
and process the output using POST method.
<?php
if (isset($_POST['name'])) {
$name = $_POST['name'];
$address = $_POST['address'];
$email = $_POST['email'];
$college = $_POST['college'];
$major = $_POST['major'];
$course = $_POST['course'];
echo "Name: " . $name . "<br>";
echo "Address: " . $address . "<br>";
echo "Email: " . $email . "<br>";
echo "College: " . $college . "<br>";
echo "Major: " . $major . "<br>";
echo "Course: " . $course . "<br>";
}
?>
This is a basic example of a contact form, where the user can enter their name, address, email,
college, major and course. Once the user submits the form, the form data is sent to the PHP
script "submit.php" using the POST method. The PHP script receives the form data using the
$_POST array and processes it by printing the values of the form fields on the screen.
3. Write an embedded PHP script which displays the factorial of all numbers from 1 to 10 in
a table in the web page. The factorial should be calculated and returned from a function.
The table headings should be "Number" and "Factorial".
This is an example of a simple PHP script that displays the factorial of all numbers from 1 to
10 in an HTML table. It uses a function called factorial() to calculate the factorial of a given
number. The function uses a recursive approach to calculate the factorial by multiplying the
number by the factorial of the number – 1 until the number reaches 0. Then it returns 1. This
function is called for all numbers from 1 to 10 inside a for loop. The for loop is used to create
a new row in the table for each number and the corresponding factorial. The output will be a
table with two columns, “Number” and “Factorial” and 10 rows, one for each number from 1
to 10.
1. What is Route Model Binding in Laravel? Which types of route model binding are
supported in Laravel?
There are two types of route model binding supported in Laravel: implicit and explicit.
Implicit Route Model Binding: This type of binding automatically matches the value of the
route parameter to the primary key of the model class and returns an instance of that model.
The naming convention for the route parameter must match the name of the primary key
column in the database table.
Explicit Route Model Binding: This type of binding requires that you specify the method to be
used to retrieve the model instance. This allows you to use a custom column other than the
primary key for matching the route parameter to a model.
In both types of binding, Laravel will automatically handle the case when the model is not
found and will throw an HTTP 404 exception. In summary, Route Model Binding in Laravel is
a powerful feature that allows you to easily retrieve models from the database based on a
route parameter and automatically handle cases where the model is not found.
2. Explain how Laravel performs route handling using routes calling controller methods.
Ans. In Laravel, routes are used to define the URL patterns that the application should
respond to, and the controller methods that should be called when a user visits those URLs.
When a user makes a request to a specific URL, Laravel's routing component checks the list
of defined routes to find a matching pattern. If a matching pattern is found, the corresponding
controller method is executed.
When a request is made, Laravel's routing component will match the requested URL and HTTP
method with the defined routes, and call the appropriate controller method. The controller
method can then handle the request and return a response to the user.
Laravel also supports passing parameters to controller methods through the URL. In summary,
Laravel's routing component handles the mapping of URLs to controller methods, allowing
developers to easily define how the application should respond to different types of requests
and providing a simple way to pass parameters to controllers through the URL.
3. List the data types used in JSON? Explain the use of parse() and stringify() functions in
JSON with examples.
The JSON.parse() function is used to convert a JSON string into a JavaScript object. It takes a
JSON string as an argument and returns a JavaScript object that can be used to access the
data in the JSON string.
For example:
The JSON.stringify() function is used to convert a JavaScript object into a JSON string. It takes
a JavaScript object as an argument and returns a JSON string that can be stored or
transmitted.
For example: