Download Kerala Board Solutions for Class 12 Computer Science Chapter 10 Server Side Scripting Using PHP
Access comprehensive textbook solutions for Chapter 10 Server Side Scripting Using PHP using the official curriculum guides for Class 12 Computer Science. Designed to align with the 2026-27 Kerala Board standards, these detailed answers help students reinforce core academic concepts.
Access Kerala Board Solutions and Answers
View or download the dedicated Chapter 10 Server Side Scripting Using PHP solution resource below. Engaging with these textbook answers under focused study conditions ensures continuous academic progress and mastery of the 2026-27 curriculum for Computer Science.
Previous Questions and Answers
Question 1: PHP is (March 2016)
a) freeware
b) proprietary
c) both
d) none
Answer:
a) freeware
Exam Tips:
a) PHP is open-source and free to use, which is why it is described as freeware; remember this as one of its main advantages.
Question 2: a) Compare indexed and associative arrays in PHP. (March 2016) (2 marks)
b) Write a PHP program to display the prime numbers below 50. (3 marks)
OR
Write a PHP program to display the perfect numbers below 100. (3 marks)
Answer:
a) An array in PHP is a collection of key and value pairs. Unlike C++, PHP allows either non-negative integers or strings to be used as keys. The types of arrays in PHP are indexed arrays, associative arrays and multi-dimensional arrays.
| Indexed array | Associative array |
|---|---|
| Elements are identified by numeric indices; the index of the first element is zero. | Elements are identified by named keys (string indices). |
| Created with array(value1, value2, ...) | Created with array(key1 => value1, key2 => value2, ...) |
| Example: $course = array("Science", "Commerce", "Humanities"); | Example: $course = array("Computer Science" => "05", "Commerce" => "39", "Science" => "01"); |
b) Program to display the prime numbers below 50:
<?php
echo "Prime numbers below 50";
echo "<br>============";
for($j=2;$j<50;$j++)
{
$prime=1;
for($i=2;$i<=$j/2;$i++)
{
if($j%$i==0)
{
$prime=0;
break;
}
}
if($prime==1)
echo "<br>".$j;
}
?>
OR program to display the perfect numbers below 100 (a perfect number is equal to the sum of its proper divisors):
<?php
echo "Perfect numbers below 100";
echo "<br>============";
for($j=2;$j<100;$j++)
{
$sum=0;
for($i=1;$i<=$j/2;$i++)
{
if($j%$i==0)
$sum=$sum+$i;
}
if($j==$sum)
echo "<br>".$j;
}
?>
The prime numbers printed are 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47. The perfect numbers printed are 6 and 28.
Exam Tips:
a) For a 2-mark comparison, give at least two clear differences and a short example of each array type.
b) In the programs, use a loop with a test condition and break, and always end PHP code with ?>.
c) Attempt only one of the two programs in part (b) (the OR choice).
Question 3: An array in PHP is given as follows: (May 2016)
$family = array("Father"=>"Ajay", "Son"=>"Arjun", "Daughter"=>"Archana");
Name the type of this array. Write a foreach loop that prints all the array elements. (2 marks)
Answer:
This is an associative array, because its elements are accessed using named keys (Father, Son, Daughter) instead of numeric indices.
<?php
$family = array("Father"=>"Ajay", "Son"=>"Arjun", "Daughter"=>"Archana");
foreach($family as $key=>$name)
echo "$key - $name, ";
?>
Exam Tips:
a) Write the type of array first, with a one-line reason, and then the loop.
b) In foreach with keys, the syntax is foreach($array as $key => $value).
Question 4: A web server that supports PHP on any operating system is ____________. (May 2016) (1 mark)
Answer:
Apache (or LAMP / WAMP)
Exam Tips:
a) Apache is the commonly named server; LAMP (Linux, Apache, MySQL, PHP) and WAMP (Windows version) are also accepted.
Question 5: Discuss the special data types used in PHP. (May 2016) (2 marks)
Answer:
The special data types in PHP are:
1. Null: A special data type whose only value is NULL. A variable has this value by default if no value is assigned to it. Example: $m = null;
2. Array: A collection of elements stored under one name. There are three types of arrays: indexed array, associative array and multi-dimensional array.
3. Object: Similar to objects in C++. A class must be declared first, and then objects are created using the command new.
4. Resource: It is not an actual data type but a special variable that holds a reference to a file handler, a database object and so on.
Exam Tips:
a) Name each type and give a one-line explanation of it; four types carry the marks.
b) Give the small example $m = null; for Null if space allows.
Question 6: Create an HTML form in PHP showing the difference between the GET and POST methods. (May 2016)
OR
Write a function in PHP to find the factorial of a number. (3 marks)
Answer:
The difference between the GET and POST methods is given below.
| GET method | POST method |
|---|---|
| 1) Faster | 1) Slower |
| 2) Used to send a small volume of data | 2) Used to send a large volume of data |
| 3) Up to 2000 characters | 3) No limit |
| 4) Less secure | 4) More secure |
| 5) Data is visible during submission | 5) Data is not visible during submission |
| 6) The page link can be bookmarked | 6) The page link cannot be bookmarked |
OR (factorial program)
Step 1: Open a notepad, type the following and save it as fact_form.html in the htdocs folder of the web server (for example C:\Abyss Web Server\htdocs).
<html>
<head>
<title>
factorial
</title>
</head>
<body bgcolor="cyan">
<form method="post" action="fact.php">
Enter a number
<input type="text" name="num">
<br>
<input type="submit" value="submit">
</form>
</body>
</html>
Step 2: Open another notepad, type the following and save it as fact.php in the same folder.
<?php
function factorial()
{
$num=$_POST['num'];
$fac=1;
for($i=1;$i<=$num;$i++)
$fac=$fac*$i;
echo "The factorial of ".$num." is ".$fac;
}
factorial();
?>
Step 3: Start the web server, open a browser and type http://localhost/fact_form.html in the address bar.
Exam Tips:
a) For the difference, write at least five points in the two-column table form.
b) For the factorial program, show the form file and the PHP file separately and mention the file names.
c) Take the input with $_POST (the form method is post) and use a loop that multiplies from 1 to the number.
Practice Questions and Answers
Question 7: Write a PHP program to display the multiplication table of 5.
Answer:
<?php
echo "Multiplication table of 5";
echo "<br>=================";
for($i=1;$i<=10;$i++)
{
echo "<br>".$i." * 5=".$i*5;
}
?>
Exam Tips:
a) Use a for loop from 1 to 10 and print the product in each pass.
Question 8: Write a PHP program to display all palindrome numbers between 100 and 200.
Answer:
<?php
echo "Palindrome numbers between 100 and 200";
echo "<br>=================";
for($i=100;$i<=200;$i++)
{
$n=$i;
$rev=0;
while($n>0)
{
$rem=$n%10;
$rev=($rev*10)+$rem;
$n=($n-$rem)/10;
}
if($i==$rev)
echo "<br>".$i;
}
?>
A number is a palindrome if it is equal to its reverse, for example 101, 111, 121, ..., 191.
Exam Tips:
a) Reverse each number using % 10 to get the last digit and integer division by 10 to remove it.
b) Compare the reversed number with the original number to decide.
Question 9: Write a PHP program to display all Armstrong numbers below 1000.
Answer:
<?php
echo "Armstrong numbers below 1000";
echo "<br>=================";
for($i=1;$i<1000;$i++)
{
$n=$i;
$arm=0;
while($n>0)
{
$rem=$n%10;
$arm=$arm+$rem*$rem*$rem;
$n=($n-$rem)/10;
}
if($i==$arm)
echo "<br>".$i;
}
?>
The Armstrong numbers below 1000 are 1, 153, 370, 371 and 407.
Exam Tips:
a) An Armstrong number (of three digits) is equal to the sum of the cubes of its digits, for example 153 = 1 + 125 + 27.
b) Extract the digits with % 10 and add the cube of each digit.
Question 10: Display the following table using PHP and HTML. Each cell should display the row number and column number of the cell. Use a PHP loop statement to generate the table.
(Figure: a table with 5 columns headed Column1 to Column5 and 10 rows; the cell in row r and column c shows "row r, col c".)
Answer:
<html>
<head>
<title>
Table
</title>
</head>
<body>
<?php
echo "<table border=1>";
echo "<tr>";
echo "<th><center>Column1</center></th>";
echo "<th><center>Column2</center></th>";
echo "<th><center>Column3</center></th>";
echo "<th><center>Column4</center></th>";
echo "<th><center>Column5</center></th>";
echo "</tr>";
for($i=1;$i<=10;$i++)
{
echo "<tr>";
for($j=1;$j<=5;$j++)
{
echo "<td align=center>row ".$i.", col ".$j."</td>";
}
echo "</tr>";
}
echo "</table>";
?>
</body>
</html>
Exam Tips:
a) Use nested loops: the outer loop creates the rows (1 to 10) and the inner loop creates the cells (1 to 5).
b) Print the heading row separately before the loops, using the th tag.
Question 11: Write a PHP program to find the biggest of three numbers.
Answer:
<!DOCTYPE HTML>
<html lang="en">
<head>
<title>
biggest of three
</title>
</head>
<body bgcolor="cyan">
<form method="post" name="biggest">
Enter number 1
<input type="text" name="num1"><br>
Enter number 2
<input type="text" name="num2"><br>
Enter number 3
<input type="text" name="num3"><br>
<input type="submit" value="Maximum">
</form>
<?php
if(isset($_POST['num1']))
{
$num1=$_POST['num1'];
$num2=$_POST['num2'];
$num3=$_POST['num3'];
echo "The biggest of ".$num1.", ".$num2." and ".$num3." is ";
if($num1>=$num2 && $num1>=$num3)
echo $num1;
elseif($num2>=$num1 && $num2>=$num3)
echo $num2;
else
echo $num3;
}
?>
</body>
</html>
Exam Tips:
a) Compare the numbers using the logical operator && inside if ... elseif ... else.
b) Use >= so that the program also works when two numbers are equal.
Question 12: Create a registration form which contains the fields Name, Roll No, Gender and a submit button. Write a PHP script which accepts these details and displays them back on the browser when the user clicks the submit button.
Answer:
Step 1: Open a notepad, type the following and save it as practiceQ6.html.
<html lang="en">
<head>
<title>
form
</title>
</head>
<body bgcolor="cyan">
<form method="post" action="practiceQ6.php">
Enter Name:
<input type="text" name="name"><br>
Enter Roll No:
<input type="text" name="rollno"><br>
Enter Gender:
Male<input type="radio" name="sex" value="M">
Female<input type="radio" name="sex" value="F">
<input type="submit" value="Submit">
</form>
</body>
</html>
Step 2: Open another notepad, type the following and save it as practiceQ6.php.
<!DOCTYPE HTML>
<html lang="en">
<head>
<title>
form
</title>
</head>
<body bgcolor="cyan">
<?php
$names=$_POST['name'];
$rollno=$_POST['rollno'];
$gender=$_POST['sex'];
echo "<br>Name:-".$names;
echo "<br>Roll No:-".$rollno;
echo "<br>Gender:-".$gender;
?>
</body>
</html>
Step 3: Run the first file (practiceQ6.html) in the browser, fill in the details and click Submit.
Exam Tips:
a) The action attribute of the form must be the name of the PHP file that receives the data.
b) Read each value with $_POST using the name given to the input field.
Question 13: Write a PHP script for the following. Design a form to accept a string. Write a function to count the total number of vowels (a, e, i, o, u) in the string.
Answer:
Step 1: Open a notepad, type the following and save it as test.html.
<html>
<head>
<title>
form
</title>
</head>
<body bgcolor="cyan">
<form method="post" action="test2.php">
Enter a string:
<input type="text" name="str"><br>
<input type="submit" value="submit">
</form>
</body>
</html>
Step 2: Open another notepad, type the following and save it as test2.php.
<?php
function noOfVowels()
{
$str=$_POST['str'];
$vow=0;
for($i=0;$i<strlen($str);$i++)
{
switch($str[$i])
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
$vow++;
}
}
echo "The number of vowels is ".$vow;
}
noOfVowels();
?>
Output: for the input "computer" the page shows "The number of vowels is 3".
Exam Tips:
a) Visit each character with the loop variable and test it with switch-case; several cases can share one statement.
b) Use strlen() to find the number of characters in the string.
Question 14: Create a table in MySQL and insert a few records. Write a PHP script to display the inserted records on a browser.
Answer:
Step 1: Open MySQL and create a table as follows.
create table stock(itemcode int primary key,
name char(25),
qty int, price decimal(8,2));
insert into stock values(101,'Pears',200,45.5);
insert into stock values(102,'Lux',100,28.5);
insert into stock values(103,'Rexona',250,27.5);
select * from stock;
| itemcode | name | qty | price |
|---|---|---|---|
| 101 | Pears | 200 | 45.50 |
| 102 | Lux | 100 | 28.50 |
| 103 | Rexona | 250 | 27.50 |
Step 2: Open a notepad, type the following and run it.
<?php
$user_name="root";
$password="password";
$server="localhost";
$database="mysql";
$db_handle=mysql_connect($server,$user_name,$password);
if(!$db_handle)
{
die('Could not connect: '.mysql_error());
}
$db_found=mysql_select_db($database,$db_handle);
if($db_found)
{
$SQL="Select * from stock";
$select_query=mysql_query($SQL);
echo "<table border=1>";
echo "<tr>";
echo "<th><center>Item Code</center></th>";
echo "<th><center>Name</center></th>";
echo "<th><center>Quantity</center></th>";
echo "<th><center>Price</center></th>";
echo "</tr>";
while($record=mysql_fetch_array($select_query))
{
echo "<tr>";
echo "<td>".$record['itemcode']."</td>";
echo "<td>".$record['name']."</td>";
echo "<td>".$record['qty']."</td>";
echo "<td>".$record['price']."</td>";
echo "</tr>";
}
echo "</table>";
}
else
{
echo "Data base not Found";
}
mysql_close($db_handle);
?>
Output: a table with the columns Item Code, Name, Quantity and Price showing the three records.
Exam Tips:
a) Follow the steps in order: connect, select the database, run the query, fetch the rows and close the connection.
b) Use a while loop with mysql_fetch_array() to print every record.
c) Note: the mysql_ functions follow the syllabus; newer PHP versions use the mysqli_ functions for the same steps.
Question 15: Create a table in MySQL and insert a few records. Write a PHP script to accept a value using a form, search the value in the database and display the record on a browser.
Answer:
Step 1: Open a notepad, type the following and save it as practiceQ9.html.
<html>
<head>
<title>
form
</title>
</head>
<body bgcolor="cyan">
<form method="post" action="practiceQ9.php">
Enter the Item code:
<input type="text" name="itemcode"><br>
<input type="submit" value="submit">
</form>
</body>
</html>
Step 2: Open another notepad, type the following and save it as practiceQ9.php (the table stock created in the previous question is used).
<?php
$user_name="root";
$password="password";
$server="localhost";
$database="mysql";
$itemcode=$_POST['itemcode'];
$db_handle=mysql_connect($server,$user_name,$password);
if(!$db_handle)
{
die('Could not connect: '.mysql_error());
}
$db_found=mysql_select_db($database,$db_handle);
if($db_found)
{
$SQL="Select * from stock where itemcode=".$itemcode;
$select_query=mysql_query($SQL);
echo "<table border=1>";
echo "<tr>";
echo "<th><center>Item Code</center></th>";
echo "<th><center>Name</center></th>";
echo "<th><center>Quantity</center></th>";
echo "<th><center>Price</center></th>";
echo "</tr>";
while($record=mysql_fetch_array($select_query))
{
echo "<tr>";
echo "<td>".$record['itemcode']."</td>";
echo "<td>".$record['name']."</td>";
echo "<td>".$record['qty']."</td>";
echo "<td>".$record['price']."</td>";
echo "</tr>";
}
echo "</table>";
}
else
{
echo "Data base not Found";
}
mysql_close($db_handle);
?>
Step 3: Run the file practiceQ9.html, enter an item code such as 102 and click submit.
Output: the record 102, Lux, 100, 28.50 is displayed in a table.
Exam Tips:
a) The search value comes from the form through $_POST and is used in the where clause of the SQL query.
b) Remember to give the same file names in the form action and while saving the files.
Assess Questions and Answers
Question 16: Which of the following functions returns 1 when the output is successful?
a) echo()
b) print()
c) both
d) None
Answer:
b) print()
Exam Tips:
a) print returns 1 on successful output, while echo returns nothing.
Question 17: Which of the following printing constructs accepts multiple parameters?
a) echo
b) print
c) printf
d) All of the above
Answer:
a) echo
Exam Tips:
a) echo can take several comma-separated values; print takes only one.
Question 18: Which one of the following should not be used while sending a password or other sensitive information?
a) Get
b) Post
c) Request
d) Next
Answer:
a) Get
Exam Tips:
a) GET shows the data in the URL, so never use it for passwords.
Question 19: Which of the following functions returns the number of characters in a string variable?
a) count($variable)
b) len($variable)
c) strcount($variable)
d) strlen($variable)
Answer:
d) strlen($variable)
Exam Tips:
a) strlen() gives the length of a string; count() is used for arrays.
Question 20: Which of the following variables is not a predefined variable?
a) $_GET
b) $ASK
c) $_REQUEST
d) $_POST
Answer:
b) $ASK
Exam Tips:
a) Predefined (superglobal) variables begin with an underscore, such as $_GET, $_POST and $_REQUEST.
Question 21: When the $_GET variable is used to collect data, the data is visible to
a) none
b) only you
c) everyone
d) selected few
Answer:
c) everyone
Exam Tips:
a) GET data appears in the address bar, so everybody can see it.
Question 22: When the $_POST variable is used to collect data, the data is visible to
a) none
b) only you
c) everyone
d) selected few
Answer:
a) none
Exam Tips:
a) POST data is sent inside the request body and is not shown in the URL.
Question 23: Which variable is used to collect form data sent with both the GET and POST methods?
a) %Both
b) $_Both
c) $Request
d) $_REQUEST
Answer:
d) $_REQUEST
Exam Tips:
a) $_REQUEST collects data sent by GET, POST and cookies.
Question 24: Which one of the following parameters is not used in mysql_connect()?
a) database host
b) user ID
c) password
d) database name
Answer:
d) database name
Exam Tips:
a) The database is selected separately with mysql_select_db().
Question 25: Study the following steps and determine the correct order:
i) Open a connection to the MySQL server
ii) Execute the SQL query
iii) Fetch the data from the query
iv) Select the database
v) Close the connection
a) 1, 4, 2, 3, 5
b) 4, 1, 2, 3, 5
c) 1, 5, 4, 2, 1
d) 4, 1, 3, 2, 5
Answer:
a) 1, 4, 2, 3, 5 (that is, i, iv, ii, iii, v)
Exam Tips:
a) Connect first, then select the database, run the query, fetch the data and finally close the connection.
Question 26: What is PHP?
Answer:
PHP was formerly known as Personal Home Pages. Nowadays PHP stands for PHP: Hypertext Preprocessor. It is a server-side scripting language that normally runs on a web server.
Exam Tips:
a) Give both the old and the new expansion of PHP; the recursive name "PHP: Hypertext Preprocessor" is the one used now.
Question 27: What is the difference between PHP and JavaScript?
Answer:
JavaScript is a client-side script. Client-side scripts run faster but have limitations; the source code can be viewed by the user, so they are less secure.
PHP is executed on the server and only the result is sent back to the client (browser), so it is impossible to view the PHP source code.
Exam Tips:
a) Write the two points: where the code runs (client or server) and whether the source can be viewed.
b) You can add that PHP is better suited for database access.
Question 28: What are the steps involved in running a PHP program?
Answer:
Type the code in a notepad. PHP code begins with <?php and ends with ?>. Save the file with the extension .php in the root directory of the web server.
Step 1: Type the following and save it as first.php in the htdocs folder (for example C:\Abyss Web Server\htdocs).
<?php
echo "My first PHP web page";
?>
Step 2: Start the web server if it is off.
Step 3: Type http://localhost/first.php in the address bar of the browser.
Output: My first PHP web page
Exam Tips:
a) Remember the three steps: write and save the .php file in the web server root folder, start the server, open the file through localhost.
Question 29: What is the use of "echo" in PHP?
Answer:
echo is an output statement. It can produce multiple outputs in one statement, and the parentheses are optional.
Example:
echo "first output", "second output";
When parentheses are used, only a single value can be given: echo ("first output");
Exam Tips:
a) Mention that echo can take more than one parameter, unlike print.
Question 30: What is the use of "print" in PHP?
Answer:
print is an output statement used to produce a single output. It takes only one parameter and is slower than echo. It returns 1 (TRUE) on successful printing.
Example:
print "only one output";
print ("only one output");
Exam Tips:
a) Remember: one parameter and a return value of 1.
Question 31: What are the differences between the "echo" and "print" statements?
Answer:
| echo | |
|---|---|
| Can take more than one parameter | Takes only one parameter |
| Does not return any value | Returns 1 on successful printing |
| Faster | Slower |
Exam Tips:
a) Write the answer as a two-column table with at least three points.
Question 32: Why is PHP superior to client-side languages such as JavaScript?
Answer:
Client-side scripts (JavaScript) run faster but have limitations; their source code can be viewed, so they are less secure. PHP is executed on the server and the result is sent back to the browser, so the PHP source code cannot be viewed.
Benefits of PHP:
1) PHP can be easily embedded into HTML, and a static website can easily be converted into a dynamic one.
2) It is compatible with almost all databases.
3) It is platform-independent and can run on almost all operating systems (Windows, Linux, Mac).
4) It is simple and easy to learn.
5) It uses a very small amount of system resources and runs fast.
6) PHP provides security to prevent malicious attacks.
7) It has the support of the open-source community.
8) It is free software and can be used to develop all types of websites.
Exam Tips:
a) Start with the main point (server-side execution, hidden source code) and then list the benefits.
b) Write at least four benefits.
Question 33: Which character is used to terminate a PHP statement? Name one situation where omitting this termination character does not produce an error.
Answer:
Every PHP statement must end with a semicolon (;).
The exception is the last statement of a PHP block: the semicolon is not compulsory before the closing tag ?>.
Exam Tips:
a) Answer both parts: the character (semicolon) and the exception (last statement before the closing tag).
Question 34: What is an escape sequence? Name three commonly used escape sequences.
Answer:
An escape sequence is a character preceded by a backslash (\), used to print special characters.
| Escape sequence | Definition | Example | Output |
|---|---|---|---|
| \" | To print " | echo "Say \"PHP\"" | Say "PHP" |
| \' | To print ' | echo 'X\'ian' | X'ian |
| \n | New line | echo "BVM \nHSS" | BVM HSS (a new line in the page source) |
| \t | Tab space | echo "BVM\tHSS" | BVM HSS (a tab in the page source) |
| \r | Carriage return | ||
| \$ | To print $ | echo "100\$" | 100$ |
| \\ | To print \ | echo "\\n is used as new line" | \n is used as new line |
Exam Tips:
a) Any three sequences with their use are enough, for example \n, \t and \$.
b) Give a small example with each to earn full marks.
Question 35: What will be the output of the following PHP scripts?
a) <?php
echo "Today looks \nbright and sunny";
?>
b) <?php
echo "ours not to question why;";
echo "ours but to do and die";
?>
c) <?php
$x = 8;
$y = 8;
echo ($x == $y);
?>
Answer:
a) Today looks bright and sunny (the \n creates a new line only in the page source; the browser shows the text on one line)
b) ours not to question why;ours but to do and die (both echo statements print on the same line)
c) 1 (the condition is true, and true is printed as 1)
Exam Tips:
a) Remember that a browser ignores a newline in HTML output unless <br> is used.
b) A true comparison prints 1; a false one prints nothing.
Question 36: Find the error in each of the following PHP scripts:
a) <?php
/* print a line of output /
echo 'hello'
?>
b) <?php
echo '<p align="right">Copyright Me, 2008</p>';
?>
c) <?php
echo 'Line 1;
?>
Answer:
a) There is an error: the comment is not terminated (it should end with */). The correct code is:
<?php
/* print a line of output */
echo 'hello';
?>
b) No error.
c) The string must be enclosed in matching quotes. The correct code is:
<?php
echo 'Line 1';
?>
Exam Tips:
a) A comment started with /* must end with */.
b) Every string needs both an opening and a closing quote.
Question 37: What are the different types of loops in PHP?
Answer:
Loops in PHP are the while loop, the do-while loop, the for loop and the foreach loop.
a) while loop: It is an entry-controlled loop. The loop variable must be initialised outside the loop. The expression is evaluated first; the body is executed only if it is true, and the loop variable is updated inside the body. The body is executed until the expression becomes false.
Syntax:
while(expression)
{
Body of the loop;
Update loop variable;
}
Example:
<?php
$i=10;
while($i>0)
{
echo "$i\t";
$i--;
}
?>
b) do-while loop: This loop executes at least once, because the condition is tested after the body. The body is executed until the expression becomes false.
Syntax:
do
{
Body of the loop;
Update loop variable;
}while(expression);
Example:
<?php
$i=10;
do
{
echo "$i\t";
$i--;
}while($i>0);
?>
c) for loop:
Syntax:
for(initialisation; testing; updation)
{
Body of the for loop;
}
Example:
<!DOCTYPE HTML>
<html lang="en">
<head>
<title>
We are learning PHP
</title>
</head>
<body bgcolor="cyan">
<?php
for($i=10;$i>0;$i--)
echo "$i\t";
?>
</body>
</html>
d) foreach loop (an extension of the for loop): It is used when the number of elements in an array is not known in advance. There are two forms.
(i) foreach($array_variable_name as $value): There is no need to specify the starting and ending index; the array pointer moves one element at a time.
Syntax:
foreach($array_variable_name as $value)
{
Body of the loop;
}
Example:
<?php
$course=array("Computer Science","Commerce","Science");
foreach($course as $value)
echo "$value".",";
?>
(ii) foreach($array_variable_name as $key=>$value): The value of the current array element is assigned to $value and its key is assigned to $key.
Syntax:
foreach($array_variable_name as $key=>$value)
{
Body of the loop;
}
Example:
<?php
$course=array("Computer Science","Commerce","Science");
foreach($course as $key=>$code)
echo "$key-$code".",";
?>
Exam Tips:
a) Name all four loops first, then explain each with syntax and a small example.
b) Highlight that do-while is exit-controlled and runs at least once, while while and for are entry-controlled.
c) The foreach loop is used only with arrays.
Question 38: How do we declare an array in PHP?
Answer:
In PHP an array is a collection of key and value pairs. Unlike C++, PHP allows either non-negative integers or strings to be used as keys.
Types of arrays in PHP: indexed arrays, associative arrays and multi-dimensional arrays.
1. Indexed arrays: The elements are identified by indices, and the index of the first element is zero. The function array() is used to create an array.
Syntax:
$array_name=array(value1,value2,.......);
OR
$array_variable[key]=value;
Examples:
$mark=array(60,70,80);
$course=array("Science","Commerce","Humanities");
or
$mark[0]=60;
$mark[1]=70;
$mark[2]=80;
$course[0]="Science";
$course[1]="Commerce";
$course[2]="Humanities";
Program:
<!DOCTYPE HTML>
<html lang="en">
<head>
<title>
We are learning PHP
</title>
</head>
<body bgcolor="cyan">
<?php
$course=array("Science","Commerce","Humanities");
for($i=0;$i<3;$i++)
echo $course[$i].",";
?>
</body>
</html>
2. Associative arrays: Arrays with named keys (string indices) are called associative arrays.
Syntax:
$variable_name=array(key1=>value1,key2=>value2,etc);
Example:
<!DOCTYPE HTML>
<html lang="en">
<head>
<title>
We are learning PHP
</title>
</head>
<body bgcolor="cyan">
<?php
$course=array("Computer Science"=>"05","Commerce"=>"39","Science"=>"01");
echo "The code of Computer Science is ".$course["Computer Science"];
?>
</body>
</html>
Exam Tips:
a) Use the array() function in the answer and show one syntax for indexed and one for associative arrays.
b) The index of an indexed array starts at 0.
Question 39: What is the importance of the "action" attribute in an HTML form?
Answer:
The action attribute of an HTML form specifies the name of the file to which the form data is submitted. When the submit button is clicked, the data is sent to the file named in the action attribute.
Exam Tips:
a) Mention that the file in action is usually the PHP script that processes the data.
Question 40: How can we extract the string "hotmail.com" from the string "scert@hotmail.com"?
Answer:
Find the position of the character @ in the string and copy all the characters after it into a new string.
<?php
$str="scert@hotmail.com";
echo "<br>The given string is ".$str;
for($i=0;$i<strlen($str);$i++)
{
if($str[$i]=='@')
{
$pos=$i;
break;
}
}
$j=0;
$newstr="";
for($i=$pos+1;$i<strlen($str);$i++)
{
$newstr[$j]=$str[$i];
$j++;
}
echo "<br>The substring is ".$newstr;
?>
Output:
The given string is scert@hotmail.com
The substring is hotmail.com
Exam Tips:
a) Explain the logic in two steps: find the position of @ and copy the characters after it.
b) PHP also has the built-in function substr() for this purpose.
Question 41: What will be the output of the following code?
$a = 10;
if($a>5 or $a<15)
echo "true";
else
echo "false";
Answer:
The condition uses the logical OR operator, and the code is written as follows:
<?php
$a=10;
if($a>5 or $a<15)
echo 'true';
else
echo 'false';
?>
The output is true.
Exam Tips:
a) With "or", the condition is true when at least one part is true; here both are true.
Question 42: What will be the output of the following code? (1 mark)
function fn($var)
{
$var = $var - ($var/10*5);
return $var;
}
echo fn(100);
Answer:
The output is 50.
Steps: 100/10 = 10, 10 * 5 = 50, so 100 - 50 = 50.
Exam Tips:
a) Solve the bracket first and then the subtraction.
Question 43: How do superglobal arrays help programming in PHP?
Answer:
Superglobals are special variables that are available to all programs and in all scopes.
| Superglobal | Purpose |
|---|---|
| $GLOBALS | Global scope variables are available |
| $_SERVER | Information about the server |
| $_GET | Data passed using the HTTP GET method |
| $_POST | Data passed using the HTTP POST method |
| $_REQUEST | Data passed via an HTTP request |
| $_FILES | Data passed by an HTML file input |
| $_SESSION | Current session data specific to the user |
| $_COOKIE | Data stored in the browser |
Exam Tips:
a) Describe what a superglobal is, then list at least four of them with their purposes.
Question 44: What is the use of $_SERVER?
Answer:
$_SERVER returns the paths and script locations of the server.
| Code | Description |
|---|---|
| $_SERVER["PHP_SELF"] | Returns the file name of the currently executing script |
| $_SERVER["SERVER_NAME"] | Returns the host server name |
| $_SERVER["SCRIPT_NAME"] | Same as $_SERVER["PHP_SELF"] |
Example:
<!DOCTYPE HTML>
<html lang="en">
<head>
<title>
We are learning PHP
</title>
</head>
<body bgcolor="cyan">
<?php
echo $_SERVER['PHP_SELF']."<BR>";
echo $_SERVER['SERVER_NAME']."<BR>";
echo $_SERVER['SCRIPT_NAME']."<BR>";
?>
</body>
</html>
Output (for a file named global2.php on a local server):
global2.php
localhost
global2.php
Exam Tips:
a) List the three common elements with their descriptions.
b) Mention that $_SERVER is a superglobal array.
Question 45: What are the differences between the GET and POST methods in form submitting? (5 marks)
Answer:
| GET method | POST method |
|---|---|
| 1. Faster | 1. Slower |
| 2. To send a small volume of data | 2. To send a large volume of data |
| 3. Up to 2000 characters | 3. No limit |
| 4. Less secure | 4. More secure |
| 5. Data is visible during submission | 5. Data is not visible during submission |
| 6. The page link can be bookmarked | 6. The page link cannot be bookmarked |
Exam Tips:
a) For 5 marks write at least five differences.
b) The security point is the most important one for the examiner.
Question 46: While submitting a form, the URL displayed in the address bar was http://localhost:8080/check2.php?exam=March2014&web=www.dhsekerala.gov…. Can you identify which method was used here?
Answer:
The GET method was used, because all the submitted data is displayed in the URL during submission.
Exam Tips:
a) The data after the ? in the URL is the sign of the GET method.
Question 47: While trying to open a dynamic web page from a bookmark saved earlier, the web page did not show properly. What could be the reason for this?
Answer:
The data submission method used was POST. In the POST method the variables are not displayed in the URL, so the page cannot be bookmarked and it does not display properly when opened from a bookmark.
Exam Tips:
a) Link the answer to the fact that POST data is not part of the URL.
Question 48: How do we create a MySQL connection?
Answer:
To access data from a database, the PHP program first establishes a connection to the database server (MySQL) and then specifies the database to use. The steps are:
1) Open a connection to MySQL.
2) Specify the database we want to open.
3) Retrieve data from, or insert data into, the database.
4) Close the connection.
Exam Tips:
a) Write the steps in the correct order; the connection is opened with mysql_connect() and closed with mysql_close().
Question 49: How do we select a MySQL database from PHP?
Answer:
A MySQL server may contain many databases. The function mysql_select_db() is used to select a particular database. It returns true if it finds the database, otherwise false.
Syntax: mysql_select_db($database);
Example:
<?php
$user_name="root";
$password="password";
$server="localhost";
$database="mysql";
$db_handle=mysql_connect($server,$user_name,$password);
if(!$db_handle)
{
die('Could not connect: '.mysql_error());
}
echo 'Connected Successfully';
$db_found=mysql_select_db($database);
if($db_found)
{
echo "Data base Found";
}
else
{
echo "Data base not Found";
}
mysql_close($db_handle);
?>
Output: Connected SuccessfullyData base Found
Exam Tips:
a) Mention that mysql_select_db() returns true or false.
b) Newer versions of PHP use mysqli_select_db() for the same purpose.
Question 50: How do we execute an SQL query? How do we fetch its result?
Answer:
There are two steps:
a) Execute the SQL query on the database using the function mysql_query().
Syntax:
$result_set=mysql_query(query, connection);
b) Fetch a row from the result using the function mysql_fetch_array().
$result_set=mysql_query(query, connection);
$fetched_row=mysql_fetch_array($result_set);
Exam Tips:
a) Name the two functions: mysql_query() to execute and mysql_fetch_array() to fetch a row.
b) Use a while loop to fetch all the rows one by one.
Free study material for Computer Science
Free Kerala Board Textbook Explanations: Class 12 Computer Science Chapter 10 Server Side Scripting Using PHP
Official Kerala Board Solutions for Chapter 10 Server Side Scripting Using PHP
Review comprehensive exercise answers for Class 12 Computer Science Chapter 10 Server Side Scripting Using PHP. Fully updated to match current Kerala Board syllabus guidelines, these textbook solutions help students verify their work and maintain accurate study notes.
Step-by-Step Explanations for Chapter 10 Server Side Scripting Using PHP
Beyond providing final answers, these guides offer step-by-step breakdowns for complex queries in the Class 12 Computer Science module. This approach helps students balance theoretical depth with practical problem-solving skills required for Kerala Board exams.
Next Steps in Your Computer Science Revision
Consistent practice with these solution guides cultivates faster problem-solving habits and clearer logical structuring. For a complete preparation experience, pair these textbook answers with our dedicated revision notes and sample papers for Class 12 Computer Science.
FAQs
The complete and updated Kerala Plus Two Computer Science Previous Questions Chapter 10 Server Side Scripting Using PHP is available for free on StudiesToday.com. These solutions for Class 12 Computer Science are as per latest Kerala Board curriculum.
Yes, our experts have revised the Kerala Plus Two Computer Science Previous Questions Chapter 10 Server Side Scripting Using PHP as per 2026 exam pattern. All textbook exercises have been solved and have added explanation about how the Computer Science concepts are applied in case-study and assertion-reasoning questions.
Toppers recommend using Kerala Board language because Kerala Board marking schemes are strictly based on textbook definitions. Our Kerala Plus Two Computer Science Previous Questions Chapter 10 Server Side Scripting Using PHP will help students to get full marks in the theory paper.
Yes, we provide bilingual support for Class 12 Computer Science. You can access Kerala Plus Two Computer Science Previous Questions Chapter 10 Server Side Scripting Using PHP in both English and Hindi medium.
Yes, you can download the entire Kerala Plus Two Computer Science Previous Questions Chapter 10 Server Side Scripting Using PHP in printable PDF format for offline study on any device.