0% found this document useful (0 votes)
1K views

WBP Summer 2023 Model Answer Paper

The document provides important instructions for examiners assessing the Summer 2023 examination for the subject 'Web Based Application Development Using PHP'. It outlines guidelines for evaluating answers based on understanding rather than exact wording, and includes specific questions and model answers related to PHP programming concepts. Additionally, it addresses the use of both English and Marathi for first-year students in AICTE diploma programs.

Uploaded by

patil8694srush
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views

WBP Summer 2023 Model Answer Paper

The document provides important instructions for examiners assessing the Summer 2023 examination for the subject 'Web Based Application Development Using PHP'. It outlines guidelines for evaluating answers based on understanding rather than exact wording, and includes specific questions and model answers related to PHP programming concepts. Additionally, it addresses the use of both English and Marathi for first-year students in AICTE diploma programs.

Uploaded by

patil8694srush
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

- SUMMER – 2023 EXAMINATION

Subject: Web Based Application Development Using PHP (Elect-II) Subject Code:
22619

Important Instructions to examiners:


1) The answers should be examined by key words and not as word-to-word as given in the
model answer scheme.
2) The model answer and the answer written by candidate may vary but the examiner may
try to assess the understanding level of the candidate.
3) The language errors such as grammatical, spelling errors should not be given more
Importance (Not applicable for subject English and Communication Skills.
4) While assessing figures, examiner may give credit for principal components indicated in
the figure. The figures drawn by candidate and model answer may vary. The examiner
may give credit for any equivalent figure drawn.
5) Credits may be given step wise for numerical problems. In some cases, the assumed
constant values may vary and there may be some difference in the candidate’s answers
and model answer.
6) In case of some questions credit may be given by judgement on part of examiner of
relevant answer based on candidate’s understanding.
7) For programming language papers, credit may be given to any other program based on
equivalent concept.
8) As per the policy decision of Maharashtra State Government, teaching in English/Marathi
and Bilingual (English + Marathi) medium is introduced at first year of AICTE diploma
Programme from academic year 2021-2022. Hence if the students in first year (first and
second semesters) write answers in Marathi or bilingual language (English +Marathi), the
Examiner shall consider the same and assess the answer based on matching of concepts
with model answer.
Q.No Sub Answer Marking
Q.N. Scheme
1. Attempt any FIVE of the following: 10M
a) State the advantages of PHP(any four) 2M
Ans. The advantages of PHP are as follows: State any four
1. Open Source and Free of Cost: advantages
People can download it from an open-source and get it for free. 1/2M each
2. Platform Independence:
PHP-based applications can run on any OS such as UNIX, Windows, Linux,
etc.
3. Database connection:
It has a built-in database connection that helps to connect databases and
reduce the trouble and the time to develop web applications or content-based
sites altogether.
4. Library support:
PHP has strong library support using which one can utilize the various
function modules for data representation.

Page 1 / 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

- SUMMER – 2023 EXAMINATION

Subject: Web Based Application Development Using PHP (Elect-II) Subject Code:
22619

5. User-friendly:
It has a less learning curve, and one can learn it quickly.
6. Flexible:
It is highly flexible, and people can readily use it to combine its function
with various other programming languages.
7. PHP uses its own memory space, so the workload of the server and
loading time reduces automatically, which results into the faster processing
speed.
8.PHP has multiple layers of security to prevent threats and malicious
attacks.
b) State the use of strlen() and strrev() 2M
Ans. Strlen(): Use of each
The strlen() function is used to count number of characters in a string. It method- 1M
returns the length of a string.

Strrev():
The strrev() function is used to reverse a string.
c) Define introspection 2M
Ans. Introspection is the ability of a program to examine object characteristics Correct
definition 2M
such as its name, parent class, properties and method.
d) Enlist the attributes of cookies. 2M
Ans. Attributes of Cookies are as follows: List any four
1. name attributes 1/2M
each
2. value
3. expire
4. path
5. domain
6. secure
e) Write syntax of constructing PHP webpage with MySQL 2M
Ans. Using MySQLi object-oriented procedure: Correct syntax
Syntax: 2M
<?php
$servername = "localhost";
$username = "username";
$password = "password";
// Creating connection
$conn = new mysqli($servername, $username, $password);
// Checking connection
Page 2 / 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

- SUMMER – 2023 EXAMINATION

Subject: Web Based Application Development Using PHP (Elect-II) Subject Code:
22619

if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>

OR

Using MySQLi procedural procedure :


Syntax:
<?php
$servername = "localhost";
$username = "username";
$password = "password";
// Creating connection
$conn = mysqli_connect($servername, $username, $password);
// Checking connection
if (!$conn)
{
die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully";
?>
Note: Any one relevant syntax shall be considered
f) Define GET & POST methods 2M
Ans. GET method:
GET method is a way to pass data entered in a form, to the server or Each definition
1M
destination by adding it into URL.
OR
It processes the client request which is sent by the client, using the HTTP get
method. Browser uses get method to send request.

POST method:
POST method is a way to pass data entered in form to the server securely
without adding it to URL.
OR
It Handles request in servlet which is sent by the client. If a client is entering
registration data in an html form, the data can be sent using post method.

Page 3 / 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

- SUMMER – 2023 EXAMINATION

Subject: Web Based Application Development Using PHP (Elect-II) Subject Code:
22619

g) State the use of “$” sign in PHP 2M


Ans. $ sign in PHP is used to indicate a variable. Correct use 2M
A variable starts with the $ sign, followed by the name of the variable.
Example:
$a=10

2. Attempt any THREE of the following: 12M


a) Write a program using do-while loop. 4M
Ans. <?php Correct
$n=1; program 4M
do{
echo "$n<br/>";
$n++;
}while($n<=10);
?>

Note: Any other relevant program shall be considered


b) Explain associative and multi dimensional arrays 4M
Ans. Associative Arrays
Explanation of
The associative arrays are very similar to numeric arrays in term of each 2M
functionality but they are different in terms of their index. Associative array
will have their index as string so that you can establish a strong association
between key and values.
Example
<?php
$salaries = array(
"mohammad" => 2000, "Dinesh" => 1000, "Surabhi" => 500
);
echo "Salary of Arjun is ". $salaries['Arjun'] . "<br />";
echo "Salary of Dinesh is ". $salaries['Dinesh']. "<br />";
echo "Salary of Surabhi is ". $salaries['Surabhi']. "<br />";
echo "<pre>";
print_r($salaries);
echo "</pre>";
?>

Page 4 / 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

- SUMMER – 2023 EXAMINATION

Subject: Web Based Application Development Using PHP (Elect-II) Subject Code:
22619

Multidimensional Arrays
In multi-dimensional array, each element in the main array can also be an
array. A multidimensional array is an array containing one or more arrays. It
has more than one dimension in the form of rows and columns. Values in the
multi-dimensional array are accessed using multiple indexes. Example:

In this example we create a two dimensional array to store marks of three


students in three subjects:
<?php
$marks = array(
"Arjun" => array
("physics" => 35, "maths" => 30, "chemistry" => 39),
"Dinesh" => array
("physics" => 30, "maths" => 32, "chemistry" => 29),
"Surabhi" => array
("physics" => 31, "maths" => 22, "chemistry" => 39)
);
/* Accessing multi-dimensional array values */
echo "Marks for Arjun in physics : " ;
echo $marks['Arjun']['physics'] . "<br />";
echo "Marks for Dinesh in maths : ";
echo $marks['Dinesh']['maths'] . "<br />";
echo "Marks for Surabhi in chemistry : " ;
echo $marks['Surabhi']['chemistry'] . "<br />";
echo "<pre>";
print_r($marks);
echo "</pre>";
?>
OR
$cars = array (array("Volvo",22,18), array("BMW",15,13),
array("Ciaaz",10,15));
OR
$row0 = array("Volvo",22,18);
$row1 = array("BMW",15,13);
$row2 = array("Ciaaz",10,15);

Page 5 / 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

- SUMMER – 2023 EXAMINATION

Subject: Web Based Application Development Using PHP (Elect-II) Subject Code:
22619

$cars = array($row0, $row1, $row2);


Note: Any other relevant example shall be considered

c) Define serialization and explain it with example 4M


Ans. Definition:
The serialize() function converts a storable representation of a value. Correct
definition 2M
To serialize data means to convert a value to a sequence of bits, so that it can And any
be stored in a file, a memory buffer, or transmitted across a network. suitable
Syntax example 2M
serialize(value);
Example:
<?php
$data = serialize(array("Red", "Green", 4044));
echo $data;
?>
Output:
a:3:{i:0;s:3:"Red";i:1;s:5:"Green";i:2;i:4044;}
d) Describe the procedure of sending email. 4M
Ans. 1. PHP mail is the built-in PHP function that is used to send emails from PHP Correct
scripts. procedure 4M
2. The mail function accepts the following parameters;
a) Email address
b) Subject
c) Message
d) CC or BCC email addresses
3. The PHP mail function has the following basic syntax
<?php
mail($to_email_address,$subject,$message,[$headers],[$parameters]);
?>
HERE,
a) “$to_email_address” is the email address of the mail recipient
b) “$subject” is the email subject
c) “$message” is the message to be sent.
d) “[$headers]” is optional, it can be used to include information such as
CC, BCC
 CC is the acronym for carbon copy. It‟s used when you want to send a
copy to an interested person i.e. a complaint email sent to a company can
also be sent as CC to the complaints board.

Page 6 / 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

- SUMMER – 2023 EXAMINATION

Subject: Web Based Application Development Using PHP (Elect-II) Subject Code:
22619

 BCC is the acronym for blind carbon copy. It is similar to CC. The email
addresses included in the BCC section will not be shown to the other
recipients.
4. PHP mailer uses Simple Mail Transmission Protocol (SMTP) to send mail.
On a hosted server, the SMTP settings would have already been set. The
SMTP mail settings can be configured from “php.ini” & “sendemail.ini”
file in the PHP installation folder.

Php Mail Example


<?php
$to_email = 'name @ company . com';
$subject = 'Testing PHP Mail';
$message = 'This mail is sent using the PHP mail function';
$headers = 'From: noreply @ company . com';
mail($to_email,$subject,$message,$headers);
?>
3. Attempt any THREE of the following: 12M
a) Differentiate between implode and explode functions. 4M
Ans.
Implode function Explode function Any 4 correct
points-1M each
The implode function works on an The explode function works on a
array. string.
The implode function returns string. The explode function returns array.

The first parameter of the implode The first parameter of the explode
function is optional. function is required.
Syntax: Syntax:
string implode(string $seperator, array explode(string
array $array) separator,string string)
Example: Example:
<?php <?php
$arr = array('CO','IF','EJ'); $str = "CO-IF-EJ";
$str = implode(" ",$arr); $arr = implode("-",$str);
echo $str; print_r($arr);
?> ?>

Page 7 / 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

- SUMMER – 2023 EXAMINATION

Subject: Web Based Application Development Using PHP (Elect-II) Subject Code:
22619

b) Explain the concept of cloning of an object 4M


Ans.  The clone keyword is used in PHP‟s to copy object.
 does a shallow copy and so, any changes made in the cloned object will Explanation
not affect the original object. 2M
 __clone is a magic method in PHP. Magic methods are predefined in PHP Example 2M
and start with “__” (double underscore). They are executed in response to
some events in PHP.

Example:
<?php
// Creating instance of Animals class
$objAnimals = new Animals();
// Assigning values
$objAnimals->name = "Lion";
$objAnimals->category = "Wild Animal";
// Cloning the original object
$objCloned = clone $objAnimals;
$objCloned->name = "Elephant";
$objCloned->category = "Wild Animal";
print_r($objAnimals);
print_r($objCloned);
?>
c) Describe the procedure of validation of web page 4M
Ans. Validating a web page in PHP involves checking the input data provided by
Explanation
users to ensure that it meets the required criteria and is safe for further 3M
processing. Here's a general procedure for validating a web page in PHP:
The procedure of validation of web page.
Define the Validation Rules: Determine the validation rules for each input Example 1M
field on the web page. This includes constraints such as required fields, data
formats (e.g., email, date), length limits, and any specific patterns or
restrictions.
Create the HTML Form: Design and create the HTML form that collects
user input. Specify the appropriate input types, such as text, email, number,
etc., and include any necessary attributes like required or pattern.

Page 8 / 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

- SUMMER – 2023 EXAMINATION

Subject: Web Based Application Development Using PHP (Elect-II) Subject Code:
22619

Submitting the Form: Set up the PHP script that processes the form
submission. This script will be responsible for handling the validation and
processing the data. Ensure that the form's method attribute is set to "POST"
so that the data is sent securely.

Retrieve and Sanitize Input: In the PHP script, retrieve the submitted data
using the $_POST superglobal array. Sanitize the input to remove any
unwanted characters or tags that could potentially pose security risks. You
can use functions like htmlspecialchars or filter_input to sanitize specific
inputs.

Perform Validation: Apply the validation rules defined in Step 1 to each


input field. Use PHP's conditional statements, loops, and regular expressions
to check if the input data meets the required criteria. For example, you can
use if statements and regular expressions to validate email addresses, check
for empty fields, or validate numeric values.

Display Validation Errors: If any input fails validation, store the error
messages in an array or variable. Display these error messages next to the
corresponding input fields on the web page, informing the user about the
specific validation issues they need to address.

Process Valid Data: If all the input data passes validation, proceed with
further processing, such as storing the data in a database, sending emails, or
performing other necessary operations.

Redisplay Form with Pre-filled Data: If there are validation errors,


redisplay the form with the user's previously submitted data already filled in.
This provides a better user experience and allows users to correct the invalid
fields without re-entering all the data.
Example:
if($_SERVER["REQUEST_METHOD"] == "POST"){
// Validate name
if(empty(trim($_POST["name"]))){

Page 9 / 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER – 2023 EXAMINATION


-
Subject: Web Based Application Development Using PHP (Elect-II) Subject Code:
22619

$name_err = "Please enter your name.";


} else{
$name = trim($_POST["name"]);
}
}
d) Write update and delete operations on table data 4M
Ans. Update operations:
 The UPDATE statement is used to change or modify the existing records Correct
in a database table. operation
 SQL query will be formed using the UPDATE statement and WHERE statement 2M
each
clause, after that a query will be executed by passing it to the PHPquery()
function to update the tables records.
Example:
The percentage of roll no. C101 will be updated to ‟98.99‟ from student
table by using UPDATE statement.
<?php
require_once 'login.php';
$conn = new mysqli($hn, $un, $pw, $db);
if ($conn->connect_error) die($conn->connect_error);
$query = "UPDATE student SET percent=98.99
WHERE rollno='CO101'";
$result = $conn->query($query);
if (!$result) die ("Database access failed: " . $conn->error);
?>
Delete operation:
 Records can be deleted from a table using the SQL DELETE statement.
 SQL query is formed using the DELETE statement and WHERE clause,
after that will be executed by passing this query to the PHP query()
function to delete the tables records.
 For example a student record with a roll no. „CO103‟ will be deleted by
using DELETE statement and WHERE clause.
<?php
require_once 'login.php';
$conn = new mysqli($hn, $un, $pw, $db);

Page 10 / 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

- SUMMER – 2023 EXAMINATION

Subject: Web Based Application Development Using PHP (Elect-II) Subject Code:
22619

if ($conn->connect_error) die($conn->connect_error);
$query = "DELETE from student WHERE rollno='CO103'";
$result = $conn->query($query);
if (!$result) die ("Database access failed: " . $conn->error);
?>
4. Attempt any THREE of the following: 12M
a) State user defined functions and explain it with example. 4M
Ans. A function is a named block of code that performs a specific task.PHP
supports user defined functions, where user can define his own functions. Correct
explanation -
A function doesn't execute when its defined, it executes when it is called.
2M
The syntax to create a PHP user defined function –
A PHP user-defined function declaration starts with the keyword function as
shown below – Any correct
function funName($arg1, $arg2, ... $argn) Example-2M
{
// code to be executed inside a function
//return $val
}
The syntax to call a PHP user-defined function –
$ret=funName($arg1, $arg2, ... $argn);
Example:
<?php
// user-defined function definition
function printMessage(){
echo "Hello, How are you?";
}
//user-defined function call
printMessage();
?>
As in the above program, the printMessage() function is created using the
keyword function. The function prints the message “Hello, How are you?”.
So, farther in the program when it is calling the function as
“printMessage();”. It prints a message, as we can see in the above output.

Page 11 / 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER – 2023 EXAMINATION


-
Subject: Web Based Application Development Using PHP (Elect-II) Subject Code:
22619

b) Describe inheritance, overloading, overriding and cloning object. 4M


Ans. Inheritance allows classes to inherit properties and methods from a parent
Each term
class, overloading provides dynamic property and method handling, description 1M
overriding enables customization of inherited methods, and cloning
creates copies of objects.

1. Inheritance: Inheritance is a fundamental concept in object-oriented


programming that allows classes to inherit properties and methods from
another class. In PHP, we can define a new class by extending an existing
class using the extends keyword. The new class is called the child or derived
class, and the existing class is called the parent or base class. The child class
inherits all the public and protected properties and methods of the parent
class. It can also add its own properties and methods or override the parent
class's methods.
2. Overloading: In PHP, overloading refers to the ability to dynamically
create properties and methods in a class at runtime. There are two types of
overloading:
a. Property Overloading: PHP provides the __set() and __get() magic
methods to handle property overloading. When a property is accessed or
modified that doesn't exist or is inaccessible within the class, these methods
are called, allowing us to define custom logic for handling the property.
b. Method Overloading: PHP doesn't support method overloading in the
traditional sense (having multiple methods with the same name but different
parameters). However,we can use the __call() magic method to handle
method overloading. It gets called when a non-existent or inaccessible
method is invoked, giving the flexibility to handle the method dynamically.
3. Overriding: Overriding occurs when a child class provides its own
implementation of a method that is already defined in the parent class. The
method signature (name and parameters) in the child class must match that of
the parent class. By overriding a method, we can customize the behaviour of
the method in the child class while retaining the same method name. To
override a method in PHP, simply declare the method in the child class with
the same name as the parent class's method.

Page 12 / 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

- SUMMER – 2023 EXAMINATION

Subject: Web Based Application Development Using PHP (Elect-II) Subject Code:
22619

4. Cloning Objects: Cloning an object in PHP allows us to create a duplicate


of an existing object. The clone is a separate instance of the class, but its
properties will initially have the same values as the original object. In PHP,
we can clone an object using the clone keyword followed by the object you
want to clone. The cloning process involves calling the __clone() magic
method if it's defined in the class. This method allows us to customize the
cloning process by modifying the properties of the cloned object if necessary.

c) Explain web server role in web development 4M


Ans. The web server's role in PHP web development as shown below:
Any relevant
Diagram 1M

Explanation
3M

1. HTTP Request Handling: When a user accesses a PHP-based web


application, their browser sends an HTTP request to the web server. The web
server receives this request and determines how to handle it based on the
requested URL and the HTTP method used (e.g., GET, POST). The server is
responsible for routing the request to the appropriate PHP script or file for
processing.
2. PHP Script Execution: Once the web server receives an HTTP request
that requires PHP processing, it passes the request to the PHP interpreter or
engine. The PHP interpreter executes the PHP code contained within the
requested file or script. It processes the logic, interacts with databases,
performs computations, and generates dynamic HTML or other types of
content.
3. Server-Side Processing: PHP is a server-side scripting language, meaning
the PHP code is executed on the server before the resulting HTML or other
output is sent back to the client's browser. The web server runs the PHP script
in its environment and provides necessary resources like database
connections, file access, and session management.
4. Integration with Other Technologies: In addition to executing PHP code,
the web server may also be responsible for integrating with other technologies
commonly used in web development. For example, the web

Page 13 / 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

- SUMMER – 2023 EXAMINATION

Subject: Web Based Application Development Using PHP (Elect-II) Subject Code:
22619

server can handle requests for static files like CSS, JavaScript, and images,
delivering them directly to the client without involving PHP processing. It
can also handle URL rewriting or redirection for search engine optimization
(SEO) purposes or to create user-friendly URLs.
5. Content Delivery: Once the PHP script execution is complete, the web
server sends the generated content (usually HTML) back to the client's
browser as an HTTP response. The server sets the appropriate headers, such
as Content-Type, Content-Length, and caching directives, to ensure the
correct interpretation and rendering of the response by the client.
6. Error Handling and Logging: The web server is responsible for handling
errors and logging relevant information. If an error occurs during PHP script
execution, the web server can be configured to display an error message or
redirect to a custom error page. It also logs information about requests, errors,
and server events, which can be helpful for debugging, monitoring, and
performance analysis.

d) Explain inserting & Retrieving the query result operations. 4M


Ans. Insert operation:
Data can be inserted into an existing database table with an INSERT INTO Insertion with
example- 2M
query.SQL query using the INSERT INTO statement with appropriate values,
after that we will execute this insert query through passing it to the PHP
query() function to insert data in table.
Retrieving with
For example a student data is inserted into a table example-2M
using INSERT INTO statement.

<?php
require_once 'login.php';
$conn = new mysqli($hn, $un, $pw, $db);
if ($conn->connect_error) die($conn->connect_error);
$query = "INSERT INTO student(rollno,name,percent) VALUES
('CO103','Reena Patel',98.45)";
$result = $conn->query($query);
if (!$result) die ("Database access failed: " . $conn->error);
?>

Page 14 / 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

- SUMMER – 2023 EXAMINATION

Subject: Web Based Application Development Using PHP (Elect-II) Subject Code:
22619

Retrieving operation:
The data can be retrieved from the table using SQL SELECT statement which
is used to select the records from database tables.
SQL query using the SELECT statement will be executed by passing this
SQL query to the PHP query() function to retrieve the table data.

For example data from the student table can be executed by using the
SELECT statement.
select_sample.php
<?php
require_once 'login.php';
$conn = new mysqli($hn, $un, $pw, $db);
if ($conn->connect_error) die($conn->connect_error);
$query = "SELECT * FROM student";
$result = $conn->query($query);
if (!$result) die ("Database access failed: " .
$conn->error);
$rows = $result->num_rows;
echo "<table
border='1'><tr><th>RollNo.</th><th>Name</th><th>Percentage</th></tr>";
for ($j = 0 ; $j < $rows ; ++$j)
{
$result->data_seek($j);
$row = $result->fetch_array(MYSQLI_NUM);
echo "<tr>";
for ($k = 0 ; $k < 3 ; ++$k) echo
"<td>$row[$k]</td>";
echo "</tr>";
}
echo "</table>";
?>
e) Create a web page using GUI components 4M
Ans. <!DOCTYPE html>
<html> Correct syntax
of any four
<head> GUI
<title>Registration form</title> components
<link rel="stylesheet" href="styel.css" type="text/css">
</head> 1M for each
component

Page 15 / 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

- SUMMER – 2023 EXAMINATION

Subject: Web Based Application Development Using PHP (Elect-II) Subject Code:
22619

<body>
<div class="main">
<div class="register">
<h2>Register Here</h2>
<form id="register" action="registrationform.php" method="post">

<label>First name:</label>
<br>
<input type="text" id="fname" name="fname" placeholder="Enter your first
name">
<br>
<br>

<label>Last name:</label>
<br>
<input type="text" id="lname" name="lname" placeholder="Enter your last
name">
<br>
<br>

<label for="email">Enter your email:</label>


<br>
<input type="email" id="email" name="email" placeholder="Enter valid
email">
<br>
<br>

<label>Date of Birth:</label>
<br>
<input type="date" id="dob" name="dob" placeholder="Enter your
Birthday">
<br>
<br>

<label>Gender:</label>
<br>
&nbsp;&nbsp;&nbsp;
<input type="radio" id="male" name="gender"
value="male"> &nbsp;

Page 16 / 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

- SUMMER – 2023 EXAMINATION

Subject: Web Based Application Development Using PHP (Elect-II) Subject Code:
22619

<span id="male">Male</span>
&nbsp;&nbsp;&nbsp;&nbsp;
<input type="radio" id="female" name="gender"
value="female"> &nbsp;
<span id="female">Female</span>

<br>
<br>

<label>Enter mobile number:</label><br><br>


<input type="tel" id="mobno" name="mobno" placeholder="Enter
your mobile number" pattern="[7-9]{1}[0-9]{9}" required> <br>

<br>

<label>Select Usertype</label>
<br>
<select name="usertype" id="usertype">
<option value="Student">Student</option>
<option value="Staff">Staff</option>
<option value="Alumni">Alumni</option>
</select>
<br>
<br>

<label>Password:</label>
<br>
<input type="password" id="pwd" name="password" placeholder="Enter
your password" pattern ="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}" title="Must
contain at least one number and one uppercase and lowercase letter, and at
least 8 or more characters" required>

<br>
<br>

<input type="submit" id="submit" name="submit" value="Submit">

</form>
</div><!-----end of register--->

Page 17 / 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

- SUMMER – 2023 EXAMINATION

Subject: Web Based Application Development Using PHP (Elect-II) Subject Code:
22619

</div><!-----end of main---->
</body>
</html>
5. Attempt any TWO of the following 12M
a) Implement any three data types used in PHP with illustration 6M
Ans. Data Types :
PHP provides eight types of values, or data types: Implementation
Four are scalar (single-value) types: integers, floating-point numbers, strings, / example of
and Booleans. any three data
Two are compound (collection) types: arrays and objects. types -2Meach
Two are special types: resource andNULL.

Integers: Integers are whole numbers, such as 1, 12, and 256. Integer literals
can be written in decimal, octal, or hexadecimal.
Example :
Decimal1998 ,−641 , +33
Octal0755 // decimal 493 , 010 // decimal 8
Hexadecimal0xFF // decimal 255 ,0x10 // decimal 16 , -0xDAD1 // decimal
−56017
Binary numbers begin with 0b, followed by a sequence of digits (0 and 1).
Like other values, you can include a sign in binary numbers: 0b01100000 //
decimal 1 ,0b00000010 // decimal 2

Floating-Point Numbers: Floating-point numbers (often referred to as real


numbers) represent numeric values with decimal digits. This allows numbers
between 1.7E−308 and 1.7E+308 with 15 digits of accuracy.
PHP recognizes floating-point numbers written in two different formats.
General format :3.14 , 0.017 , -7.1
Scientific format: 0.314E1 // 0.314*10^1, or 3.14 , 17.0E-3 // 17.0*10^(-3),
or 0.017
Floating-point values are only approximate representations of numbers. For
example, on many systems 3.5 is actually represented as 3.4999999999.
Strings: As strings are very common in web applications, PHP includes core-
level support for creating and manipulating strings. A string is a sequence of
characters of arbitrary length. String literals are delimited by either single or
double quotes: 'big dog' or "fat hog" .
Example: $no=10;
$str1=” My roll number is $no”
echo $str1;

Page 18 / 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

- SUMMER – 2023 EXAMINATION

Subject: Web Based Application Development Using PHP (Elect-II) Subject Code:
22619

Booleans :A Boolean value represents either true(1) or false(0). Boolean


values are often used in conditional testing. Example: $var=TRUE;

Arrays :An array holds a group of values, which you can identify by position
(a number, with zero being the first position) or some identifying name (a
string), called an associative index.
Example: The array() construct creates an array.
$person = array("Edison", "Wankel", "Crapper");
$creator = array('Light bulb' =>"Edison", 'Rotary Engine' =>"Wankel",
'Toilet' =>"Crapper");

Objects :Classes are the building blocks of object-oriented design. A class is


a definition of a structure that contains properties (variables) and methods
(functions). Once a class is defined, any number of objects can be made from
it with the new keyword, and the object‟s properties and methods can be
accessed with the -> construct:
$ed = new Person;
$ed->name('Edison');

Resource :Many modules provide several functions for dealing with the
outside world. For example, every database extension has at least a function
to connect to the database, a function to send a query to the database, and a
function to close the connection to the database. Example :$res =
database_connect();
database_query($res);

NULL :The NULL value represents a variable that has no value.


Example:
$aleph = NULL;
b) Write a program to connect PHP with MySQL 6M
Ans.
Solution1: Correct logic
<?php 3M
$servername = "localhost";
$username = "root";
$password = ""; Correct syntax
// Connection 3M
$conn = new mysqli($servername,$username, $password);

Page 19 / 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

- SUMMER – 2023 EXAMINATION

Subject: Web Based Application Development Using PHP (Elect-II) Subject Code:
22619

/ For checking if connection issuccessful or not


if ($conn->connect_error)
{
die("Connection failed: ". $conn->connect_error);
}
echo "Connected successfully";
?>

OR
Solution2:
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$conn = mysqli_connect($servername, $username, $password);
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully";
?>

OR
Solution 3:
<?php
$servername = "localhost";
$username = "username";
$password = "password";
try {
$conn = new PDO("mysql:host=$servername;dbname=myDB", $username,
$password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE,
PDO::ERRMODE_EXCEPTION);
echo "Connected successfully";
} catch(PDOException $e) {
echo "Connection failed: " . $e->getMessage();
}
?>

Page 20 / 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER – 2023 EXAMINATION


-
Subject: Web Based Application Development Using PHP (Elect-II) Subject Code:
22619

c) Explain the concept of constructor and destructor in detail. 6M


Ans. Constructor: A constructor is a special built-in method. Constructors allow
initializing object properties when an object is created. A constructor method Explanation of
execute automatically when an object is created. The 'construct' method starts Constructor
3M
with two underscores (__).T
Syntax :function __construct([argument1, argument2, ..., argumentN]) Explanation of
{ destructor 3M
/* Class initialization code */
}
The type of argument1, argument2,.......,argumentN are mixed.
Example :
<?php
class student
{
var $name;
function __construct($name)
{
$this->name=$name;
}
function display()
{
echo $this->name;
}
}
$s1=new student("xyz");
$s1->display();
?>
Destructor: A destructor is the counterpart of constructor. A destructor
function is called when the object is destroyed. A destructor function cleans
up any resources allocated to an object after the object is destroyed. A
destructor function is commonly called in two ways: When a script ends or
manually delete an object with the unset() function.The 'destruct' method
starts with two underscores (__).

Syntax :function __destruct()


{
/* Class initialization code */
}
The type of argument1, argument2,.......,argumentN are mixed.

Page 21 / 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

- SUMMER – 2023 EXAMINATION

Subject: Web Based Application Development Using PHP (Elect-II) Subject Code:
22619

Example :
<?php
class student
{
var $name;
function __construct($name)
{
$this->name=$name;
}
function __destruct()
{
echo "Destructor is executing " .$this->name;
}
}
$s1=new student("xyz");
?>
6. Attempt any TWO of the following 12M
a) Describe form controls – text box, text area, radio button, check box, list 6M
& buttons
Ans. Form Controls : Description of
each control
1. Textbox : A text box is used to enter data. It is a single line input on a web 1M
page.
Tag :<input type=“text”> : It is used to display a text box on a web page.
Attributes of <input> tag used with text box:
name=“ text” : Specify name of text box for unique identification.
maxlength=number : Specify maximum number of characters that can be
accepted in a textbox.
size=number : Specify the width of text box in number of characters.
value=“text” : Specify default text value that appears in the text box when
loaded on a web page.
Example:<input type=“text” name=“n1” maxlength=20 size=15
value=“Enter your name” >

2. Textarea : It is used to display a textbox that allow user to enter multiple


lines of text. Scrollbar is used to move up and down as well as left and right if
the contents are more than size of box.
Tag :<textarea> … </textarea> : It is used to display a multiline text box on
a web page.

Page 22 / 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

- SUMMER – 2023 EXAMINATION


Subject: Web Based Application Development Using PHP (Elect-II) Subject Code: 22619

Attributes:
name=“ text” : Specify name of the element for unique identification.
cols=number : Specify width of the text area.
rows=number : Specify height of the text area.
readonly : Specify a text area as read only element.
Example:<textarea name=“t1” cols=10 rows=10>Enter your
suggestions</textarea>

3. Radio / option button : Radio buttons are used to display multiple options
from which user can select only one option. When a radio button is selected
by user, a dot symbol appears inside button. Multiple option buttons are
group together to allow user to select only one option from the group. A
group can be created by giving same name to all option buttons in that group.
Tag :<input type=“radio”> : It is used to display a radio button on a web
page.
Attributes of <input> tag used with radio button:
name=“ text” : Specify name of radio button for unique identification.
value=“text” : Specify value to be returned to the destination if that radio
button is selected.
checked: Specify default selection
Example:<input type=“radio” name=“r1” value=“male”>male
<input type=“radio” name=“r1” value=“female” checked>female

4. Checkbox : Checkbox elements are used to display multiple options from


which user can select one or more options. When a checkbox is selected by
user, a tickmark( √ ) symbol appears inside box.
Tag: <input type=“checkbox”> : It is used to display a checkbox on a web
page.
Attributes of <input> tag used with checkbox:
name=“ text” : Specify name of checkbox for unique identification.
value=“text” : Specify value to be returned to the destination if that
checkbox is checked.
Checked: Specify default selection.
Example: <input type=“checkbox” name=“c1” value=“pen” checked>pen

Page 23 / 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

- SUMMER – 2023 EXAMINATION

Subject: Web Based Application Development Using PHP (Elect-II) Subject Code:
22619

5. Select element (list) :<select> … </select> : This tag is used to create a


drop-down list box or scrolling list box from which user can select one or
more options.
Attributes:
name=“ text” : Specify name of the element for unique identification.
size=number : Specify number of options visible in a list box on a web page.
Multiple : Allow user to select multiple option with control
key. <option> … </option> tag is used to insert item in a list.
Attributes:
value=“text” : Specify value to be sent to the server once selected by user.
selected: Specify default selection.
Example:<select name=“s1” size=2>
<option value=“ Pizza”>Pizza1 </option>
<option value=“ Burger”>Burger</option>
<option value=“ Chocolate”>Chocolate</option>
</select>
6. Note: Explanation of button OR submit button OR reset button shall be
considered
i) Button : Buttons are used to display a command button which user can
click on web page to perform some action.
Tag :<input type=“button”> : It is used to display a button on a web page.
Attributes of <input> tag used with button:
name=“ text” : Specify name of button for unique identification.
value=“text” : Specify value to be displayed on button.
Example:<input type=“button” name=“b1” value=“login”>

ii) Submit button : Submit button is used to display a command button


which user can click on web page to submit information entered in a form.
Tag :<input type=“submit”> : It is used to display a submit button on a web
page.
Attributes of <input> tag used with submit button:
name=“ text” : Specify name of submit button for unique identification.
value=“text” : Specify value to be displayed on submit button.
Example:<input type=“submit” name=“s1” value=“Submit Form”>

iii) Reset button : Reset button is used to clear all elements with their
original state after user clicks on it.

Page 24 / 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

- SUMMER – 2023 EXAMINATION

Subject: Web Based Application Development Using PHP (Elect-II) Subject Code:
22619

Tag :<input type=“reset”> : It is used to display a reset button on a web


page.
Attributes of <input> tag used with reset button:
name=“ text” : Specify name of reset button for unique identification
value=“text” : Specify value to be displayed on reset button.
Example: <input type=“reset” name=“r1” value=“Reset Form”>

b) Write a program to create pdf document in PHP 6M


Ans. <?php
require("fpdf/fpdf.php"); // path to fpdf.php Correct logic
$pdf = new FPDF(); 3M
$pdf->addPage();
$pdf->setFont("Arial", 'IBU', 16); Correct syntax
$pdf->settextcolor(150,200,225); 3M
$pdf->cell(40, 10, "Hello Out There!");
$pdf->output();
?>
c) Elaborate the following: 6M
i) _call()
Relevant
ii) Mysqli_connect()
Ans. explanation of
Function overloading : each 3M
When a class has more than one function with same name but different
number of parameters then it is referred as function overloading. A same
name function behaves differently depending on arguments / parameters
passed to it.

__call() :In PHP, for function overloading , __call() method is used. This
function is triggered while invoking overloaded methods in the object
context.The $name argument is the name of the method being called.
The $arguments argument is an enumerated array containing the parameters
passed to the $named method.

Example :
<?php
class Shape1 {
const PI1 = 3.142 ;
function __call($name1,$arg1){
if($name1 == 'area1')
switch(count($arg1)){

Page 25 / 26
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

- SUMMER – 2023 EXAMINATION

Subject: Web Based Application Development Using PHP (Elect-II) Subject Code:
22619

case 0 : return 0 ;
case 1 : return self::PI1 * $arg1[0] ;
case 2 : return $arg1[0] * $arg1[1];
}
}
}
$circle1 = new Shape1();
echo "Area of Circle= ".$circle1->area1(3);
echo "<br><br>";
$rect1 = new Shape1();
echo "Area of Rectangle= ".$rect1->area1(8,6);
?>

ii) Mysqli_connect()
Mysqli_connect() function opens a new connection to the MySQL server.

Syntax :
mysqli_connect(host, username, password, dbname)

host: Optional parameter. It specifies a host name .


username: It specify MySQL username.
Password: It specify MySQL password.
Dbname: It specify the database name to be used to connect php code.

Example :
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$conn = mysqli_connect($servername, $username, $password);
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully";
?>

Page 26 / 26

You might also like