0% found this document useful (0 votes)
4 views

php slip 16

The document is a certificate template for students of Alard College of Business Studies, confirming the completion of practical work for a specific subject. It includes a detailed index of PHP programming tasks that students must complete, covering various functionalities such as string manipulation, arithmetic operations, and database interactions. Each task is designed to enhance students' practical skills in PHP programming as part of their curriculum.

Uploaded by

Vaibhav Dukare
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

php slip 16

The document is a certificate template for students of Alard College of Business Studies, confirming the completion of practical work for a specific subject. It includes a detailed index of PHP programming tasks that students must complete, covering various functionalities such as string manipulation, arithmetic operations, and database interactions. Each task is designed to enhance students' practical skills in PHP programming as part of their curriculum.

Uploaded by

Vaibhav Dukare
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 126

ALARD COLLEGE OF BUSINESS STUDIES

CERTIFICATE

This is to certify that Mr/Ms . _________________________________________________of

Class ____________________has completed his/her practical work for subject

___________________as a part of curriculum by Alard College of Business Studies ,Savitribai

Phule Pune University, Pune during the Academic year [ ]

--------------------------- -----------------------------
Signature of Examiner Signature of Examiner
(External) (internal)

------------------------ Date of Examination


(Principal) ---------------------------

--------------------- ----------------------
(Subject Prof.) (HOD)
INDEX
NAME-
SUBJECT-
SEMESTER- YEAR-
CLASS- ROLL NO-
EXAM SEAT NO-
SUBMISSION REPORT
Pract. Date Title Page Subject Teacher
No. No. Signature
01 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) from the string. Show the
occurrences of each vowel from the string. Check
whether the given string is a palindrome or not, without
using built-in function. (Use radio buttons and the
concept of function. Use ‘include’ construct or require
stmt.)
02 Write a PHP script for the following: Design a form to
accept two strings from the user. Find the first
occurrence and the last occurrence of the small string in
the large string. Also count the total number of
occurrences of small string in the large string. Provide a
text box to accept a string, which will replace the small
string in the large string. (Use built-in functions)
03 Write a PHP script for the following: Design a form to
accept two numbers from the user. Give options to
choose the arithmetic operation (use radio buttons).
Display the result on the next form. (Use the concept of
function and default parameters. Use ‘include’ construct
or require stmt).
04 Write a PHP script for the following: Design a form to
accept two strings from the user. Find whether the small
string appears at the start of the large string. Provide a
text box to accept the string that will replace all
occurrences of small string present in the large string.
Also split the large string into separate words. (Use
regular expressions)
05 Write a PHP script for the following: Design a form to
accept the details of 5 different items, such as item
code, item name, units sold, rate. Display the bill in the
tabular format. Use only 4 text boxes.
06 Write a PHP script for the following: Design a form to
accept two strings. Compare the two strings using both
methods (= = operator &strcmp function). Append
second string to the first string. Accept the position from
the user; from where the characters from the first string
are reversed. (Use radio buttons)
07 Write a menu driven PHP program to perform the
following operations on an associative array:
08 Write a menu driven PHP program to perform the
following operations on associative arrays:
09 Write PHP script to define an interface which has
methods area(), volume(). Define constant PI. Create a
class cylinder which implements this interface and
calculate area and volume.
10 Write class declarations and member function
definitions for an employee(code, name, designation).
Design derived classes as emp_account(account_no,
joining_date) from employee and emp_sal(basic_pay,
earnings, deduction) from emp_account. Write a menu
driven PHP program a) to build a master table b) to sort
all entries c) to search an entry d) Display salary.
11 Derive a class square from class Rectangle. Create one
more class circle. Create an interface with only one
method called area(). Implement this interface in all the
classes. Include appropriate data members and
constructors in all classes. Write a PHP program to
accept details of a square, circle and rectangle and
display the area.
12 Write PHP Script to create a class account
(accno,cust_name). Derive two classes from account as
saving_acc(balance, min_amount) and
current_acc(balance, min_amount). and
current_acc(balance,
min_amount). Display a menu a) Saving Account b)
Current Account For each of this display a menu with the
following options. 1. Create account 2. Deposit 3.
Withdrawal
13 Implement calculator to convert distances between
(both ways) miles and kilometres. One mile is about
1.609 kilometres. User interface (distance.html) has one
text-input, two radio-buttons, submit and reset -buttons.
Values are posted to PHP-script (distance.php) which
calculates the conversions according the user input.
14 Using regular expressions check for the validity of
entered email-id. The @ symbol should not appear more
than once. The dot (.) can appear at the most once
before @ and at the most twice or at least once after @
symbol. The substring before @ should not begin with a
digit or underscore or dot or @ or any other special
character. (Use explode and ereg function.).
15 Write PHP program to create input form for Grocery that
displays List of grocery items with checkboxes and
create a bill according to list of items selected after
clicking submit button
16 Write a PHP program that accept customer name,
consumer number and number of electricity units
consumed from an input form and print electricity bill
from following data
17 Write a PHP program for course registration of Learner
in an institute that accept Name, Course to be admitted,
Mobile number using input form validation such as
Name should be only string of character, mobile number
should contain digits with valid length and so on. and
give feedback to Learner with registration details
including registration number.
18 Write a PHP script to create a login form with a
username and password. Once the user logs in, the
second form should be displayed to accept user details
(name, city, phoneno). If the user doesn’t enter
information within a specified time limit, expire his
session and give a warning.
19 Write a PHP script to keep track of number of times the
web page has been accessed.
20 Write a PHP script to change the preferences of your
web page like font style, font size, font color,
background color using cookie. Display selected settings
on next web page and actual implementation (with new
settings) on third web page.
21 Write a PHP script to create a form to accept student
information (name, class, address). Once the student
information is accepted, accept marks in next form (Phy,
Bio, Chem, Maths, Marathi, English).Display the mark
sheet for the student in the next form containing name,
class, marks of the subject, total and percentage
22 Write a PHP program to create a shopping mall UI. User
must be allowed to do purchase from two pages. Each
page should have a page total. The third page should
display a bill, which consists of a page total of whatever
the purchase has been done and print the total. (Use
http session tracking).
23 Write a PHP script to create a form to accept customer
information (name, address, ph-no). Once the customer
information is accepted, accept product information in
the next form (Product name, qty, rate). Display the bill
for the customer in the next form. Bill should contain the
customer information and the information of the
products entered.
24 Write a PHP script to accept username and password. If
in the first three chances, username and password
entered is correct, then display second form, otherwise
display error message.
25 Consider the following entities and their relationships
26 Consider the following entities and their relationships
Doctor (doc_no, doc_name, address, city, area) Hospital
(hosp_no, hosp_name, hosp_city) Doctor and Hospital
are related with many-many relationship. Create a RDB
in 3 NF for the above and solve following Using above
database, write a PHP script which accepts hospital
name and print information about doctors visiting /
working in that hospital in tabular format.
27 Considerer the following entities and their relationships
project(pno integer, p_name char(30), ptype
char(20),duration integer), employee (eno integer,
e_name char (20), qualification char (15), joindate
date) .The relationship between project - employee: M-
M, with descriptive attributes as start_date (date),
no_of_hours_worked (integer). Using above database
write a script in PHP to accept a project name from user
and display information of employees working on the
project.
28 Consider the following entities and their relationships
student (sno integer, s_name char(30), s_class char(10),
s_addr char(50)),teacher (tno integer, t_name char (20),
qualification char (15),experience integer). The
relationship between student-teacher: m-m with
descriptive attribute subject. Using above database write
a script in PHP to accept a teacher name from user and
display the names of students along with subjects to
whom teacher is teaching.
29 Consider the following entities and their relationships
Movie (movie_no, movie_name, release_year) Actor
(actor_no, name) Relationship between movie and actor
is many – many with attribute rate in Rs. Create a RDB in
3NF for the above and solve following Using above
database, write PHP scripts for the following:(Hint:
Create HTML form havin three radio buttons)
30 Considerer the following entities and their relationships
Student (Stud_id,name,class) Competition
(c_no,c_name,type) Relationship between student and
competition is many-many with attribute rank and year.
Create a RDB in 3NF for the above and solve the
following. Using above database write a script in PHP to
accept a competition name from user and display
information of student who has secured 1st rank in that
competition.
Slip No 1

Q1) 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) from the string. Show the occurrences of

each vowel from the string. Check whether the given string is a palindrome or not,

without using built-in function. (Use radio buttons and the concept of function. Use

‘include’ construct or require stmt.)

ANS=

S1.html

<html>

<body>

<form method="GET" action="slip.php">

Enter the String : <input type="text" name="inputStr"><br>

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

</form>

</body>

Slip.php

<html>

<head><title>page</title>

</head>

<?php

$string = $_GET['inputStr'];

$vowels = array("a"=>0,"e"=>0,"i"=>0,"o"=>0,"u"=>0);

for($i=0; $i<strlen($string); $i++) {

if(strtolower($string[$i]) == 'a') {

++$cnt;

++$vowels['a'];
}

if(strtolower($string[$i]) == 'e') {

++$cnt;

++$vowels['e'];

if(strtolower($string[$i]) == 'i') {

++$cnt;

++$vowels['i'];

if(strtolower($string[$i]) == 'o') {

++$cnt;

++$vowels['o'];

if(strtolower($string[$i]) == 'u') {

++$cnt;

++$vowels['u'];

echo "<h1>Total number of vowels found : ".$cnt."<h1>";

echo "Occurence of 'a' : ".$vowels['a']."<br>";

echo "Occurence of 'e' : ".$vowels['e']."<br>";

echo "Occurence of 'i' : ".$vowels['i']."<br>";

echo "Occurence of 'o' : ".$vowels['o']."<br>";

echo "Occurence of 'u' : ".$vowels['u']."<br>";

$str=strrev($string);

$a=strlen($string);

$f=0;

for($j=0;$j<$a;$j++)

{
if($str[$j]==$string[$j])

$f=0;

else

$f=1;

break;

if($f==0)

echo"string is palindrome";

else

echo"string is not palindrome";

?>

</body>

</html>

Output

samruddhi
Enter the String :

Submitquery

Total number of vowels found : 3


Occurence of 'a' : 1
Occurence of 'e' : 0
Occurence of 'i' : 1
Occurence of 'o' : 0
Occurence of 'u' : 1
string is not palindrome
Slip No 2

Q1) Write a PHP script for the following: Design a form to accept two strings from
the user.Find the first occurrence and the last occurrence of the small string in the
large string.Also count the total number of occurrences of small string in the large
string. Provide a text box to accept a string, which will replace the small string in
the large string. (Usebuilt-in functions).
ANS=
S2.html
<html>
<head><title>php program</title></head>
<body bgcolor='#f1284e' >
<form action='s2.php' method='post'>
<pre>
Enter 1'st string :<input type='text' name='str1'><br>
Enter 2'nd string :<input type='text' name='str2'><br>
Enter string to replace small string :<input type='text' name='str'><br>
<input type='radio' name='ch' value=1>first and last occurence<br>
<input type='radio' name='ch' value=2>total occurence<br>
<input type='radio' name='ch' value=3>replace<br>
<input type=submit value= 0k ><input type=reset value=cancel></h2>
</pre>
</form>
</body>
</html>

S2.php
<html>
<head><title>page</title>
</head>
<?php
$str1=$_POST['str1'];
$str2=$_POST['str2'];
$str=$_POST['str'];
$ch=$_POST['ch'];
$oc=0;
echo"<br>string1:: $str1<br>string2:: $str2<br>string for replace:: $str</b><br>";

if($str1>$str2)
{
switch($ch)
{
case 1: echo"<br>First occ is at possition :";echo strpos($str1,$str2);
echo"<br>Last occ is at possition :";echo strrpos($str1,$str2);
break;
case 2:$oc=substr_count($str1,$str2);
if($oc==0)
echo"<br>string '$str2' not present in string '$str1'<br>";
else
echo"<br>sub string '$str2' present $oc times in string '$str1'<br>";
break;
case 3:
$str3=str_replace($str2,$str,$str1);
echo"<br>After relacing string is::$str3";

break;
}
}
else
{
switch($ch)
{
case 1:echo"<br>First occ is at position :";echo strpos($str2,$str1);
echo"<br>Last occ is at possition :";echo strrpos($str2,$str1);
break;
case 2:$oc=substr_count($str2,$str1);
if($oc==0)
echo"<br>string '$str1' not present in string '$str2'.<br>";
else
echo"<br>sub string '$str1' present $oc times in string '$str2'.<br>";
break;
case 3:
$str3=str_replace($str1,$str,$str2);
echo"<br>After relacing string::'$str3'.";
break;
}
}

?>
<h1><a href='s2.html'>go back</a></h1>
</body>
<html>

OUTPUT
RAM
Enter 1'st string :

PATIL
Enter 2'nd string :

SEETA
Enter string to replace small string :

first and last occurence

total occurence

replace

OK Cancel

string1:: ram
string2:: patil
string for replace:: seeta

string 'patil' not present in string 'ram'

go back
Slip NO 3

Q1) Write a PHP script for the following: Design a form to accept two numbers
from the user. Give options to choose the arithmetic operation (use radio
buttons). Display the result on the next form. (Use the concept of function and
default parameters. Use ‘include’ construct or require stmt).

Solution
S3.html
<html>
<body bgcolor=pink >
<form action="s3.php" method= "GET" >
Enter first number : <input type=text name=a ><br>
Enter second number: <input type=text name=b ><br>

Operation::
<input type=radio name=c value=1>Addition.<br>
<input type=radio name=c value=2>Subtraction.<br>
<input type=radio name=c value=3>Multiplication.<br>
<input type=radio name=c value=4>Division.<br>
<input type=submit value=ok> <input type=reset value=clear>
</form>
</body>

</html>
S3.php
<html>
<head><title>page</title>
</head>
<body>
<?php
$n1 = $_GET['a'];
$n2 = $_GET['b'];
$ch = $_GET['c'];

if($ch==1)
{
$c = $n1 + $n2;
echo"addition is: $c";
}
else if($ch==2)
{
$c = $n1 - $n2;
echo"subtraction is: $c";
}
else if($ch==3)
{
$c = $n1 * $n2;
echo"multiplication is: $c";
}
else if($ch==4)
{
$c = $n1 / $n2;
echo"Division is: $c";
}
?>
</body>
</html>

Output=
12
Enter first number :
4
Enter second number:
Operation:: Addition.
Subtraction.
Multiplication.
Division.

ok clear

addition is: 16
Slip 4

C) Write a PHP script for the following: Design a form to accept two strings from the
user. Find whether the small string appears at the start of the large string. Provide a
text box to accept the string that will replace all occurrences of small string present
in the large string. Also split the large string into separate words. (Use regular
expressions )
Solution:

HTML File:

<html>

<body>

<form action='ass1b2' method=post>

<pre>

Enter first string :<input type='text' name='str1'><br>

Enter second string :<input type='text' name='str2'><br>

Enter string for replace:<input type='text' name='str3'><br></h2>

<input type='radio' name="ch" value=1>Occurence.

<input type='radio' name="ch" value=2>Replace.

<input type='radio' name="ch" value=3>split.

<input type=submit value=ok> <input type=reset value=cancel>

</pre>

</form>

</body>
</html>

PHP Function:
NOTE: PHP function is saved as "ass1b2.php"

<?php

$str1=$_POST['str1'];

$str2=$_POST['str2'];

$str3=$_POST['str3'];

$ch=$_POST['ch'];

echo"First string=$str1.<br>";

echo"Second String=$str2.<br>";

echo"String for replace=$str3.<br>";

if(strlen($str1)>strlen($str2))

switch($ch)

case 1: $pos=strpos($str1,$str2);

if($pos!=0)

echo"String '$str2' Not present at the start of '$str1'.<br>";

else

echo"String '$str2' Present at the strat of '$str1'.<br>";

break;

case 2:
$str4=str_replace($str2,$str3,$str1);

printf("\nAfter replacing string::");

echo $str4;

break;

case 3: $s=preg_split("//",$str1);

foreach($s as $v) echo "\t$v <br>";

break;

else

switch($ch)

case 1:$pos=strpos($str2,$str1);

if($pos!=0)

echo"String '$str1' Not present at the start of '$str2'.<br>";

else

echo"String '$str1' Present at the start of '$str2'.<br>";

break;

case 2: $str4=str_replace($str1,$str3,$str2);

echo "After replacing string::$str4<br>";

break;

case 3:

echo"After splitting the string::<br>";

$s=preg_split("//",$str2);
foreach($s as $v) echo "\t$v <br>";

?>

Output-:
Slip 5
C) Write a PHP script for the following: Design a form to accept the details of 5
different items, such as item code, item name, units sold, rate. Display the bill in the
tabular format. Use only 4 text boxes. (Hint : Use of explode function.)
Solution:

HTML file :

<html>

<head>

<style>

table {

border-collapse: collapse;

table, th, td {

border: 1px solid blue;

</style>

</head>

<body>

<form method="post" action="slip6_Q2.php">

<center><h1>Enter details of 5 Items </h1>

<h3>item code <input type="text" name="itemcode" placeholder="ex 11,12,13,14,15"


/></h3>

<h3>item name <input type="text" name="itemname" /></h3>


<h3>units sold <input type="text" name="unitssold" /></h3>

<h3>rate <input type="text" name="rate" /></h3>

<input type="submit" value="Submit"/>

</center>

</form>

</body>

</html>

PHP file :

<?php

$itemcode = $_POST['itemcode'];

$itemname = $_POST['itemname'];

$unitssold = $_POST['unitssold'];

$rate = $_POST['rate'];

$i_code = explode(',',$itemcode);

$i_name = explode(',',$itemname);

$i_unit = explode(',',$unitssold);

$i_rate = explode(',',$rate);

$t_amt = (($i_unit[0]*$i_rate[0])+($i_unit[1]*$i_rate[1])+($i_unit[2]*$i_rate[2])+
($i_unit[3]*$i_rate[3])+($i_unit[4]*$i_rate[4]));

echo "<table align=center border=1>";


echo "<tr><td> <b>Item Code</b> </td><td> <b>Item Name</b> </td><td><b>
Units Sold</b> </td><td> <b>Rate </b></td></tr>";

echo "<tr><td>".$i_code[0]."</td><td>".$i_name[0]."</td><td>".$i_unit[0]."</
td><td>".$i_rate[0]."</td></tr>";

echo "<tr><td>".$i_code[1]."</td><td>".$i_name[1]."</td><td>".$i_unit[1]."</
td><td>".$i_rate[1]."</td></tr>";

echo "<tr><td>".$i_code[2]."</td><td>".$i_name[2]."</td><td>".$i_unit[2]."</
td><td>".$i_rate[2]."</td></tr>";

echo "<tr><td>".$i_code[3]."</td><td>".$i_name[3]."</td><td>".$i_unit[3]."</
td><td>".$i_rate[3]."</td></tr>";

echo "<tr><td>".$i_code[4]."</td><td>".$i_name[4]."</td><td>".$i_unit[4]."</
td><td>".$i_rate[4]."</td></tr>";

echo "<tr><th colspan=4></th></tr>";

echo "<tr><th colspan=3>Total amount </th><td>".$t_amt."</td></tr>";

echo "</table>";

?>

Output-:
Slip 6
C) Write a PHP script for the following: Design a form to accept two strings.
Compare the two strings using both methods (= = operator &strcmp function).
Append second string to the first string. Accept the position from the user; from
where the characters from the first string are reversed. (Use radio buttons)
Solution:
HTML File:

<html>

<head><title> .html</title></head>

<body bgcolor="violet" >

<form action="ass1c2.php" method="post">

<pre>

Enter first string ::<input type="text" name="str1">

Enter second string::<input type="text" name="str2">

Enter position::<input type='text' name="pos">

<input type="radio" name="ch" value=1>compare

<input type="radio" name="ch" value=2>with datatype


<input type="radio" name="ch" value=3>append.

<input type="radio" name="ch" value=4>possition for reverse.

<input type="submit" value="check"> <input type="reset" value="cancel">

</pre>

</form>

</body>

</html>

PHP Function:
NOTE: PHP function is saved as "ass1c2.php"

<?php

$str1=$_POST['str1'];

$str2=$_POST['str2'];

$pos=$_POST['pos'];

$ch=$_POST['ch'];

echo"First string :: $str1.<br><br>";

echo "Second string::$str2.<br><br>";

echo"position for reverse::$pos.<br><br>";


echo"choice is::$ch.<br><br>";

switch($ch)

case 1:

if($str1==$str2)

echo"Both string are equal.<br>";

else

echo"Both string are not equal.<br>";

break;

case 2:

if($str1===$str2)

echo"Both are exat equal.<BR>";

else

echo"Both are not equal.<BR>";

break;

case 3:

echo"After appending::";

echo "$str1"."$str2";

echo"<br>";

break;

case 4: $len=strlen($str1)-$pos;

$s=substr($str1,$pos,$len);

$str4=strrev($s);

echo "After reverse::$str4.<br>";


break;

?>

Output-:
slip 7
Q.1 Write a menu driven PHP program to perform the following operations on an

associative array:

i. Display the elements of an array along with the keys.

ii. Display the size of an array

iii. Delete an element from an array from the given index.

iv. Reverse the order of each element’s key-value pair.[Hint: use array_flip()]

v. Traverse the elements in an array in random order [[Hint: use shuffle()]

Solution
<?php

$assoc_array = array("key1" => "value1", "key2" => "value2", "key3" => "value3");

while(true) {

echo "\n1. Display the elements of an array along with the keys.\n";

echo "2. Display the size of an array.\n";

echo "3. Delete an element from an array from the given index.\n";

echo "4. Reverse the order of each element’s key-value pair.\n";

echo "5. Traverse the elements in an array in random order.\n";

echo "6. Exit.\n";

echo "\nEnter your choice: ";

$choice = trim(fgets(STDIN));

switch($choice) {

case 1:
foreach($assoc_array as $key => $value) {

echo "$key => $value\n";

break;

case 2:

echo "Size of array: ".count($assoc_array)."\n";

break;

case 3:

echo "\nEnter key to delete: ";

$key = trim(fgets(STDIN));

if(array_key_exists($key, $assoc_array)) {

unset($assoc_array[$key]);

echo "Element deleted.\n";

} else {

echo "Key does not exist in the array.\n";

break;

case 4:

$assoc_array = array_flip($assoc_array);

echo "Array after flipping key-value pairs:\n";

foreach($assoc_array as $key => $value) {

echo "$key => $value\n";

break;

case 5:
$keys = array_keys($assoc_array);

shuffle($keys);

echo "Array after shuffling:\n";

foreach($keys as $key) {

echo "$key => ".$assoc_array[$key]."\n";

break;

case 6:

exit(0);

default:

echo "\nInvalid choice. Please enter a number between 1 and 6.\n";

?>

OUTPUT
1. Display the elements of an array along with the keys.

2. Display the size of an array.

3. Delete an element from an array from the given index.

4. Reverse the order of each element’s key-value pair.

5. Traverse the elements in an array in random order.

6. Exit.

Enter your choice: 1

key1 => value1


key2 => value2

key3 => value3

Enter your choice: 2

Size of array: 3

Enter your choice: 3

Enter key to delete: key1

Element deleted.

Enter your choice: 1

key2 => value2

key3 => value3

Enter your choice: 4

Array after flipping key-value pairs:

value2 => key2

value3 => key3

Enter your choice: 5


Array after shuffling:

value3 => key3

value2 => key2

Enter your choice: 6

Exit
Slip 8
Q.2 Write a menu driven PHP program to perform the following operations on associative arrays:

a) Sort the array by values (changing the keys) in ascending, descending order.

b) Also sort the array by values without changing the keys.

c) Filter the odd elements from an array.

d) Sort the different arrays at a glance using single function.

e) Merge the given arrays.

f) Find the Union, intersection& set difference of two arrays.

Solution
<html>
<body bgcolor="gold">

<?php
function is_odd($var)
{
if($var%2==1)
return $var;
}

$choice=$_POST['ch'];

$arr=array('a'=>1,'b'=>2,'c'=>3,'d'=>4,'e'=>5,'f'=>6,'g'=>7,'h'=>8);

$arr1=array('l'=>11,'m'=>22,'n'=>33,'o'=>44,'p'=>55,'q'=>66,'r'=>77,'s'=>88);

$arr2=array('a'=>10,'b'=>20,'c'=>30,'d'=>40,'e'=>50,'f'=>60,'g'=>70,'h'=>80);
switch($choice)
{
case 1:
sort($arr);
echo "Array in ascending order:<br>";
print_r($arr);
rsort($arr);
echo "<br>Array in descending order:<br>";
print_r($arr);
break;
case 2:
asort($arr);
echo "Array in ascending order:<br>";
print_r($arr);
arsort($arr);
echo "<br>Array in descending order:<br>";
print_r($arr);
break;
case 3:
print_r(array_filter($arr,'is_odd'));
break;
case 4:
array_multisort($arr,0,$arr1,1,$arr2,0);
print_r($arr);
echo "<br>";
print_r($arr1);
echo "<br>";
print_r($arr2);
echo "<br>";
break;
case 5:
print_r(array_merge($arr,$arr1));
break;
case 6:
print_r(array_intersect($arr,$arr1));
break;
case 7:
$union=array_merge($arr,$arr1);
print_r(array_unique($union));
break;
case 8:
print_r(array_diff($arr,$arr1));
break;
}

echo "<br><a href ='a2c2.html'> RETURN</a>";


?>
</font>
</body>
</html>
Output:-
Slip 9.
C) Write PHP script to define an interface which has methods area(), volume().
Define constant PI. Create a class cylinder which implements this interface and
calculate area and volume.
Solution:
HTML File:
<html>

<head><title>A4A1</title></head>

<body bgcolor="GOLD" font type='San Sarif'>

<center><h2>Implementation of Interface and Class</h2></center>

<br/>

<hr>

<form action="a4a1.php" method='POST'>

<h3>Enter radius :<input type='text' name='rad'><br/></h3>

<h3>Enter height :<input type='text' name='hit'><br/></h3>

<br/>

<br/>

<pre><input type='submit' name='submit' value='Area.'> <input type='reset' name='reset'


value='reset'>

</form>

</body>

</html>
PHP Function:
NOTE: PHP function is saved as "a4a1.php"

<?php

$r=$_POST['rad'];

$h=$_POST['hit'];

define('PPI','3.1412');

Interface fun

function area($r,$h);

function volume($r,$h);

class cylinder implements fun

function area($r,$h)

$area=(2*PPI*$r*($r+$h));
echo "<center><h3>The area of cylinder is: $area</font></center></h3>";

function volume($r,$h)

$v=(PPI*$r*$r*$h);

echo "<center><h3>The volume of cylinder is: $v</font></center></h3>";

$o=new cylinder;

$o->area($r,$h);

$o->volume($r,$h);

?>
Output-:
Slip 10
C)Write class declarations and member function definitions for an employee(code,
name, designation). Design derived classes as emp_account(account_no,
joining_date) from employee and emp_sal(basic_pay, earnings, deduction) from
emp_account. Write a menu driven PHP program a) to build a master table b) to sort
all entries c) to search an entry d) Display salary.
Solution:
<html>
<head>
<link rel="stylesheet" href="style/style.css">
</head>
<body>
<div class="container">
<div class="row py-3 " >
<div class="pt-4 col-md-5 form-group py-5 px-5" style="border:2px solid green">
<h4 class="text-center">Select following Options</h4><br>
<form action="#" method="post">
<input type="radio" name="r1" value="1" class=""> Master table<br>
<input type="radio" name="r1" id="" value="2"> Sorting By Emp_Code <br>
<div class="form-group row">
<label class="col-sm-5 col-form-label">
<input type="radio" name="r1" value="3"> Search By Name</label>
<div class="col-sm-6">
<input type="text" name="nm" class="form-control">
</div>
</div>
<input type="radio" name="r1" id="" value="4"> Display Salary <br><br>
<input type="submit" value="Submit" name="submit" class="btn btn-outline-
primary">
<input type="reset" value="Clear" class=" ml-2 btn btn-outline-danger">
</form>
</div>
<div class="col-md-7">

<?php
if(isset($_POST['submit'])){
class employee{
public $code,$name,$des;
function __construct($a,$b,$c){
$this->code=$a;
$this->name=$b;
$this->des=$c;
}
public function disemp(){
echo "<td>". $this->code ."</td><td>".$this->name."</td><td>".$this->des."</td>";
}
public function getName(){
return $this->name;
}
}
class emp_acc extends employee{
public $ano, $jdate;
function __construct($a,$b,$c,$d,$e){
parent::__construct($a,$b,$c);
$this->ano=$d;
$this->jdate=$e;
}
public function disacc(){
echo "<td>". $this->ano ."</td><td>".$this->jdate."</td>";
}
}
class emp_sal extends emp_acc{
public $bs, $earn, $ded, $total;
function __construct($a,$b,$c,$d,$e,$f,$g,$h){
parent::__construct($a,$b,$c,$d,$e);
$this->bs=$f;
$this->earn=$g;
$this->ded=$h;
$this->total = $this->bs+$this->earn-$this->ded;
}
public function dissal(){
echo "<td>".$this->bs ."</td><td>".$this->earn."</td><td>".$this->ded."</td><td>".
$this->total."</td>";
}
}
$e1[0]=new emp_sal(1,"Akash","HOD",10001,"02/02/2009",30000,1000,200);
$e1[1]=new emp_sal(2,"Akash","HOD",10002,"12/10/2012",29000,3500,400);
$e1[2]=new emp_sal(3,"Ramesh","HOD",10003,"18/11/2013",24000,2500,250);
$e1[3]=new emp_sal(4,"Swara","HOD",10004,"19/05/2015",21000,3000,650);
$e1[4]=new emp_sal(5,"Priya","HOD",10005,"26/07/2017",27000,4000,750);

$ch=$_POST['r1'];
$nm=$_POST['nm'];
$flag=0;

function mastertable($e1){
echo "<table class='table'>
<tr><thead class='thead-dark'><th>Emp code</th>
<th>Emp Name</th><th>Designation</th>
<th>Account No</th><th>Joining Date</th>
<th>Basic Pay</th><th>Earning</th>
<th>Deduction</th><th>Total Salary</th></thead></tr>";
for($i=0; $i<5; $i++){
echo "<tr>";
$e1[$i]->disemp();
$e1[$i]->disacc();
$e1[$i]->dissal();
echo "</tr>";
}
echo"</table>";
}
switch($ch){
case 1 : mastertable($e1);
break;
case 2 : echo "Sorted details <br>";
function srt($a,$b){
return strcmp($a->code,$b->code);
}
mastertable($e1);
usort($e1,"srt");
break;
case 3 :
for($i=0;$i<5; $i++){
$t=$e1[$i]->getName();
if($t==$nm){
$flag=1;
break;
}
}
if($flag==0){
echo "<div class='alert alert-danger' role='alert'>
<em>Name Not Found</em>
</div>";
}else{
echo "<div class='alert alert-success' role='alert'>
<em>Name Found</em>
</div>";
}
break;
case 4 : echo "Display Salary <br>";
echo "<table class='table'>
<tr>
<thead class='thead-dark'>
<th>Emp Name</th>
<th>Basic Pay</th>
<th>Earning</th>
<th>Deduction</th>
<th>Total Salary</th>
</tr>";
for($i=0; $i<5; $i++){
echo "<tr> <td> ";
$e1[$i]->getName();
echo "</td>";
$e1[$i]->dissal();
}
echo "</tr></table>";
break;
}
}
?>
</div>
</div>
</div>
</body>
</html>
Output-:
Slip 11
C) Derive a class square from class Rectangle. Create one more class circle. Create
an interface with only one method called area(). Implement this interface in all the
classes. Include appropriate data members and constructors in all classes. Write a
PHP program to accept details of a square, circle and rectangle and display the
area.
Solution:

HTML File:

<HTML>

<BODY bgcolor=blue>

<FORM ACTION="a4b1.php" METHOD="post">

<pre>

<h1>Circle:</h1>

Radius: <input type=text name=a><BR>

<h1>

square:</h1>

side: <input type=text name=b><BR>

<h1>

Rectangle:

</h1>

length: <input type=text name=c><BR>


Breadth: <input type=text name=d><BR>

<input type=submit value=submit> <input type="reset" value=cancel>

</pre>

</form>

</BODY>

</HTML>

PHP Function:
NOTE: PHP function is saved as "a4a1.php"

<HTML>

<BODY>

<?PHP

$a=$_POST['a'];

$b=$_POST['b'];

$c=$_POST['c'];

$d=$_POST['d'];

interface one

function area($c,$d);

class rect implements one

function area($c,$d)
{

$area=$c*$d;

echo"Area of rectangle......:".$area;

echo"<br><BR>";

class square extends rect

function area($b,$b)

$area=$b*$b;

echo"Area of Square.........:".$area;

echo"<BR><br>";

class circle

function area($a)

$area=0.5*$a*$a;

echo"Area of circle.........:".$area;

echo"<br><BR>";

$o=new rect();
$o->area($c,$d);

$s=new square();

$s->area($b,$b);

$c=new circle();

$c->area($a);

echo "<br>";

?>

<a href="a4b1.html">come back</a><br>

</BODY>

</html>

Output-:
Slip 12
C) Write PHP Script to create a class account (accno,cust_name). Derive two
classes from account as saving_acc(balance, min_amount) and current_acc(balance,
min_amount). Display a menu a) Saving Account b) Current Account For each of this
display a menu with the following options. 1. Create account 2. Deposit 3.
Withdrawal
Solution:

<!DOCTYPE html>

<html>

<body>

<form action="slip12.php" method="GET">

Please select your Account<br />

<input type="checkbox" name="check_b[]" value="saving" />Saving Account<br />

<input type="checkbox" name="check_b[]" value="current" />Current Account<br />

<select id="saving">

<option value="create">Create</option>
<option value="deposite">Deposit</option>

<option value="withderw">Withderw</option>

</select>

<input type="submit" value="sumbit" />

</form>

</body>

</html>

slip12.php

<!DOCTYPE html>

<html>

<body>
<?php

class Account {

public $acc_no;

public $acc_name;

public function __construct($acc_name, $acc_no) {

$this->acc_name = $acc_name;

$this->acc_no = $acc_no;

public function intro() {

echo "The Account name {$this->acc_name} and Account No is {$this->acc_no}.";

}
class saveing_acc extends Account {

public $blance;

public $min_amount;

public function __construct($acc_name, $acc_no, $blance,$min_amount) {

$this->acc_name = $acc_name;

$this->acc_no = $acc_no;

$this->blance = $blance;

$this->min_amount = $min_amount;

public function intro() {


echo"<table border='2'>";

echo"<tr><td>Account Name</td><td>Account
no</td><td>balance</td><td>min_balance</td></tr>";

echo "<tr><td>{$this->acc_name}</td>";

echo "<td>{$this->acc_no}</td>" ;

echo"<td>{$this->blance}</td>";

echo"<td>{$this->min_amount}</td></tr>";

class current_acc extends Account {


public $blan;

public $min_amt;

public function __construct($acc_name, $acc_no, $blan,$min_amount) {

$this->acc_name = $acc_name;

$this->acc_no = $acc_no;

$this->blan = $blan;

$this->min_amount = $min_amount;

public function intro() {

echo " <tr><td>{$this->acc_name}</td>";

echo "<td>{$this->acc_no}</td>" ;
echo "<td>{$this->blan}</td>";

echo "<td>{$this->min_amount}</td></tr> ";

echo"</table>";

$saveing_acc= new saveing_acc("Ravindra", 1111, 5000,1000);

$saveing_acc->intro();

$current_acc=new current_acc("Kiran",2222,100000,1000);

$current_acc->intro();

?>

</body>
</html>

Output-:
Slip 13
C) Implement calculator to convert distances between (both ways) miles and
kilometres. One mile is about 1.609 kilometres. User interface (distance.html) has
one text-input, two radio-buttons, submit and reset -buttons. Values are posted to
PHP-script (distance.php) which calculates the conversions according the user input.
Solution:

slip13.html

<html>

<body>

<center>

<h2> Calculate km and mile</h2>

<form action="slip13.php" method="POST">

Enter Distance :<input type="text" name="distance" /><br/>

Kms:<input type="radio" name="units" value="kms" /><br/>

Miles:<input type="radio" name="units" value="miles" />

<br/>

<input type="submit" value="submit" name="Show" />

<input type="reset" value="Reset" name="Reset" />

</form>

</center>

</body>

<html>
slip13.php

<?php

$distance=$_POST['distance'];

$units=$_POST['units'];

if($units=='kms'){

$miles=$distance/1.60934;

echo'The distance is'.round($miles).'miles.';

}else{

$kms=$distance*1.60934;

echo'The distance is'.round($kms).'kms.';

?>
Output-:
Slip 14
Q2 : Using regular expressions check for the validity of entered email-id. The @ symbol should not
appear more than once. The dot (.) can appear at the most once before @ and at the most twice or at
least once after @ symbol. The substring before @ should not begin with a digit or underscore or dot or
@ or any other special character. (Use explode and ereg function.).

<?php

// Sample email address

$email = "[email protected]";

// Regular expression pattern for email validation

$pattern = '/^(?![\d._@])[\w.]+@[a-zA-Z_]+?\.[a-zA-Z]{2,3}$/';

// Checking the validity of the email address

if (preg_match($pattern, $email)) {

echo "The email address is valid.";

} else {

echo "The email address is not valid.";

?>
Output-::
Input: [email protected]
Output: Valid Email

Input: [email protected]
Output: Valid Email

Input: ankitrai326.com
Output: Invalid Email
Invalid Email
: Invalid Email
Slip 15

15.)Write PHP program to create input form for Grocery that displays List of grocery items with
checkboxes and create a bill according to list of items selected after clicking submit button.

Solution:

slip15.html

<!DOCTYPE html>

<html>

<body>

<form action="slip15.php" method="GET">

Please select your gelosery<br />

<input type="checkbox" name="check_b[]" value="rice" />Rice<br />

<input type="checkbox" name="check_b[]" value="oils" />Oils<br />

<input type="checkbox" name="check_b[]" value="milk" />Milk<br />

<input type="checkbox" name="check_b[]" value="bread" />Bread<br />

<input type="submit" value="sumbit" />


</form>

</body>

</html>

slip15.php

<?php

$hostname="127.0.0.1";

$db_name="grecery";

$username="root";

$password="";

$connection=mysqli_connect("$hostname","$username","$password","$db_name")or

die("unable to connect");

if(!$connection){

echo"Error:Unable to connect to MySQL.<br>";

echo"<br>Debugging errno: ".mysqli_connect_errno();


echo"<br>Debugging errno: ".mysqli_connect_errno();

exit;

if($stmt =$connection->query("SELECT * FROM `bill` ")){

echo "<table border='2'>";

echo "<tr><td>sr.no</td><td>Name
Item</td><td>Quntity</td><td>Rate</td><td>Amount</td></tr>";

while($row=$stmt->fetch_assoc()){

echo "<tr><td>".$row['s.no']."</td>";

echo"<td>". $row['Name Item']."</td>";

echo "<td>".$row['Quntity']."</td>";

echo "<td>".$row['Rate']."</td>";

echo "<td>".$row['Amount']."</td></tr>";
}

echo "</table>";

?>

phpmyadmin create database:

step1:chrome type localhost/phpmyadmin

step2: create new database "grecery"

CREATE TABLE `bill` (

`s.no` int(11) NOT NULL,

`Name Item` varchar(11) NOT NULL,

`Quntity` int(11) NOT NULL,

`Rate` int(11) NOT NULL,


`Amount` int(11) NOT NULL

) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

INSERT INTO `bill` (`s.no`, `Name Item`, `Quntity`, `Rate`, `Amount`) VALUES

(1, 'Rice', 670, 35, 3500),

(2, 'Oils', 345, 120, 12222);

ALTER TABLE `bill`

ADD PRIMARY KEY (`s.no`);

ALTER TABLE `bill`

MODIFY `s.no` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT

Output-:
Slip No: 16
Sub: PHP

Slip 16 - Write a PHP program that accept customer name, consumer number and number of electricity
units consumed from an input form and print electricity bill from following data ● For first 50 units – Rs.
3.50/unit ● For next 100 units – Rs. 4.00/unit ● For next 100 units – Rs. 5.20/unit ● For units above 250 –
Rs. 6.50/unit ● Fixed meter and service charge- Rs. 150/-

Solution:

<!DOCTYPE html>

<head>

<title>PHP - Calculate Electricity Bill</title>

</head>

<?php

$result_str = $result = '';

if (isset($_POST['unit-submit'])) {

$units = $_POST['units'];

if (!empty($units)) {

$result = calculate_bill($units);

$result_str = 'Total amount of ' . $units . ' - ' . $result;

/**

* To calculate electricity bill as per unit cost

*/

function calculate_bill($units) {

$unit_cost_first = 3.50;
$unit_cost_second = 4.00;

$unit_cost_third = 5.20;

$unit_cost_fourth = 6.50;

if($units <= 50) {

$bill = $units * $unit_cost_first;

else if($units > 50 && $units <= 100) {

$temp = 50 * $unit_cost_first;

$remaining_units = $units - 50;

$bill = $temp + ($remaining_units * $unit_cost_second);

else if($units > 100 && $units <= 200) {

$temp = (50 * 3.5) + (100 * $unit_cost_second);

$remaining_units = $units - 150;

$bill = $temp + ($remaining_units * $unit_cost_third);

else {

$temp = (50 * 3.5) + (100 * $unit_cost_second) + (100 * $unit_cost_third);

$remaining_units = $units - 250;

$bill = $temp + ($remaining_units * $unit_cost_fourth);

return number_format((float)$bill, 2, '.', '');

?>

<body>

<div id="page-wrap">
<h1>Php - Calculate Electricity Bill</h1>

<form action="" method="post" id="quiz-form">

<input type="number" name="units" id="units" placeholder="Please enter no. of Units" />

<input type="submit" name="unit-submit" id="unit-submit" value="Submit" />

</form>

<div>

<?php echo '<br />' . $result_str; ?>

</div>

</div>

</body>

</html>

OUTPUT-:

Php - Calculate Electricity Bill

Total amount of 200000 - 1299470.00


Slip 17
Slip 17 - C) Write a PHP program for course registration of Learner in an institute
that accept Name, Course to be admitted, Mobile number using input form
validation such as Name should be only string of character, mobile number should
contain digits with valid length and so on. and give feedback to Learner with
registration details including registration number.

Solution-:

<!DOCTYPE html>

<html>

<head>

<title>Course Registration Form</title>

</head>

<body>

<?php

$nameErr = $courseErr = $mobileErr = "";

$name = $course = $mobile = "";

if ($_SERVER["REQUEST_METHOD"] == "POST") {

if (empty($_POST["name"])) {

$nameErr = "Name is required";

} else {

$name = test_input($_POST["name"]);

if (!preg_match("/^[a-zA-Z ]*$/",$name)) {

$nameErr = "Only letters and white space allowed";

}
if (empty($_POST["course"])) {

$courseErr = "Course is required";

} else {

$course = test_input($_POST["course"]);

if (empty($_POST["mobile"])) {

$mobileErr = "Mobile number is required";

} else {

$mobile = test_input($_POST["mobile"]);

if (!preg_match("/^[0-9]{10}$/",$mobile)) {

$mobileErr = "Invalid mobile number format";

function test_input($data) {

$data = trim($data);

$data = htmlspecialchars($data);

return $data;

?>

<h2>Course Registration Form</h2>

<p><span style="color: red;">* required field</span></p>

<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">

Name: <input type="text" name="name">

<span style="color: red;">* <?php echo $nameErr;?></span>

<br><br>
Course: <input type="text" name="course">

<span style="color: red;">* <?php echo $courseErr;?></span>

<br><br>

Mobile: <input type="text" name="mobile">

<span style="color: red;">* <?php echo $mobileErr;?></span>

<br><br>

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

</form>

<?php

if($name && $course && $mobile) {

$registrationNumber = rand(10000, 99999);

echo "<h2>Registration Details:</h2>";

echo "Name: " . $name . "<br>";

echo "Course: " . $course . "<br>";

echo "Mobile: " . $mobile . "<br>";

echo "Registration Number: " . $registrationNumber;

?>

</body>

</html>
Slip 18
Slip 18 - C) Write a PHP script to create a login form with a username and password.
Once the user logs in, the second form should be displayed to accept user details
(name, city, phone no). If the user doesn’t enter information within a specified time
limit, expire his session and give a warning .
Solution:

Html file :

<html>
<body>
<form action="slip_4-1.php" method="post">

<center>
<h2> Enter Username : <input type="text" name="name"> </h2>
<h2> Enter Password : <input type="text" name="pwd"> </h2>
<input type="submit" value="Login">
</center>

</form>
</body>
</html>

slip_4-1.php :

<?php
session_start();
$t=date("1,d-m-y h:i:s",time()+20);

if($_REQUEST['name']=='xyz’ && $_REQUEST['pwd']=='xyz')


{
?>
<html>
<body>
<h1> <u><center>enter ur details</center></u> </h1>
<form action="slip_4-2.php" method=get>
<input type='hidden' name='etime' value="<?php echo $t?>">
<h2> Enter Name : <input type=textbox name=uname> </h2><br>
<h2> Enter City : <input type=textbox name=city> </h2><br>
<h2> Enter Phone No : <input type=textbox name=pno> </h2><br>
<input type=submit name=submit value=DISPLAY>
</form>
</body>
</html>
<?php
}
else echo "<center><h1>Invalid Username Or Password</h1></center>"
?>

slip_4-2.php :

<?php
session_start();
$t=$_REQUEST['etime'];
$exp=date("1,d-m-y h:i:s",time());

if($t<$exp)
echo "<center><h1>Page Time Expired</h1></center>";
else
{
echo "<center><h2>Name : ".$_REQUEST['uname']."</h2></center>";
echo "<center><h2>City : ".$_REQUEST['city']."</h2></center>";
echo "<center><h2>Phone NO : ".$_REQUEST['pno']."</h2></center>";
session_destroy();
}
?>
Output-:
Slip 19
Slip 19 - C) Write a PHP script to keep track of number of times the web page has
been accessed.

Solution:

<html>

<body>

<SCRIPT>

function GetCookie (name)

var arg = name + "=";

var alen = arg.length;

var clen = document.cookie.length;

var i = 0;

while (i < clen)

var j = i + alen;

if (document.cookie.substring(i, j) == arg)

return getCookieVal (j);

i = document.cookie.indexOf(" ", i) + 1;

if (i == 0) break;

return null;

function SetCookie (name, value)


{

var argv = SetCookie.arguments;

var argc = SetCookie.arguments.length;

var expires = (argc > 2) ? argv[2] : null;

var path = (argc > 3) ? argv[3] : null;

var domain = (argc > 4) ? argv[4] : null;

var secure = (argc > 5) ? argv[5] : false;

document.cookie = name + "=" + escape (value) +

((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +

((path == null) ? "" : ("; path=" + path)) +

((domain == null) ? "" : ("; domain=" + domain)) +

((secure == true) ? "; secure" : "");

function DeleteCookie (name)

var exp = new Date();

exp.setTime (exp.getTime() - 1);

var cval = GetCookie (name);

document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();

var expDays = 30;

var exp = new Date();

exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

function amt()
{

var count = GetCookie('count')

if(count == null)

SetCookie('count','1')

return 1

else

var newcount = parseInt(count) + 1;

DeleteCookie('count')

SetCookie('count',newcount,exp)

return count

function getCookieVal(offset)

var endstr = document.cookie.indexOf (";", offset);

if (endstr == -1)

endstr = document.cookie.length;

return unescape(document.cookie.substring(offset, endstr));

</SCRIPT>

<SCRIPT>

document.write("You've been here <b>" + amt() + "</b> times accessed webpage.")


</SCRIPT>

</body>

</html>

Output-:
Slip 20
Slip 20 - C) Write a PHP script to change the preferences of your web page like font
style, font size, font color, background color using cookie. Display selected settings
on next web page and actual implementation (with new settings) on third web page.
Solution:

1.html-
<html>

<body>

<form action="2.php" method="get">

<center>

<b>Select font style :</b><input type=text name=s1>

<b>Enter font size : </b><input type=text name=s>

<b>Enter font color :</b><input type=text name=c>

<b>Enter background color :</b><input type=text name=b>

<input type=submit value="Next">

</center>

</form>

</body>

</html>

2.php-
<?php

echo "style is ".$_GET['s1']."

color is ".$_GET['c']."

Background color is ".$_GET['b']."


size is ".$_GET['s'];

setcookie("set1",$_GET['s1'],time()+3600);

setcookie("set2",$_GET['c'],time()+3600);

setcookie("set3",$_GET['b'],time()+3600);

setcookie("set4",$_GET['s'],time()+3600);

?>

<a href="3.php">Show</a>

3.php-
<?php

$style=$_COOKIE['set1'];

$color=$_COOKIE['set2'];

$size=$_COOKIE['set4'];

$b_color=$_COOKIE['set3'];

$msg="Genus iT Solution";

echo "<body bgcolor=$b_color>";

echo "<font color=$color size=$size face=$style>$msg";

echo "</font></body>";

?>
Output-:
Slip 21
C) Write a PHP script to create a form to accept student information (name, class,
address). Once the student information is accepted, accept marks in next form (Phy,
Bio, Chem, Maths, Marathi, English).Display the mark sheet for the student in the
next form containing name, class, marks of the subject, total and percentage.
Solution:
cookies.html

<html>

<head><title>COOKIES PROGRAM</title></head>

<body>

<form action="form2.php" method="post">

Enter name<input type="text"name="name" value=""><br>

Enter class<input type="text"name="class" value=""><br>

Enter address<input type="text"name="address" value=""><br>

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

</form>

</body>

</html>

form2.php
<?php
$name=$_POST['name'];
$class=$_POST['class'];
$address=$_POST['address'];
setcookie("name","$name",time()+3660);
setcookie("class","$class",time()+3600);
setcookie("address","$address",time()+3600);
?>
<html>
<body>
<head><title>ACCEPT THE MARKS OF SUBJECT</title></head>
<form action="form3.php" method="post">
Enter MARKS OF PHYSICS<input type="text"name="phy" value=""><br>
Enter MARKS OF CHEM<input type="text"name="chem" value=""><br>
Enter MARKS OF BIOLOGY<input type="text"name="bio" value=""><br>
Enter MARKS OF MATHS<input type="text"name="maths" value=""><br>
Enter MARKS OF MARATHI<input type="text"name="marathi" value=""><br>
Enter MARKS OF ENGLISH<input type="text"name="eng" value=""><br>
<input type="submit"name="submit" value="submit">
</form>
</body>
</html>

form3.php

<?php
$x=$_COOKIE['name'];
$y=$_COOKIE['class'];
$z=$_COOKIE['address'];
$bio=$_POST['bio'];
$chem=$_POST['chem'];
$maths=$_POST['maths'];
$mara=$_POST['marathi'];
$eng=$_POST['eng'];
$phy=$_POST['phy'];
$total=$chem+$bio+$phy+$maths+$mara+$eng;
$per=$total/6.0;
?>
<html>
<table border="2">
<tr>
<th colspan="2">MARKSHEET</th>
</tr>
<tr>
<td colspan="2"><b>NAME:</b><?php echo "$x"?><br>
<b>CLASS:</b><?php echo "$y"?><br>
<b>ADDRESS:</b><?php echo "$z"?><br>
</tr>
<tr>
<td colspan="2">PHYSICS
<td><?php echo "$phy"?></td>
</tr>
<tr>
<td colspan="2">CHEMISTRY
<td><?php echo "$chem"?></td>
</tr>
<tr>
<td colspan="2">BIOLOGY
<td><?php echo "$bio"?></td>
</tr>
<tr>
<td colspan="2">MATHS
<td><?php echo "$maths"?></td>
</tr>
<tr>
<td colspan="2">MARATHI
<td><?php echo "$mara"?></td>
</tr>
<tr>
<td colspan="2">ENGLISH
<td><?php echo "$eng"?></td>
</tr>
<tr>
<td colspan="2">TOTAL
<td><?php echo "$total"?></td>
</tr>
<tr>
<td colspan="2">PERCENTAGE
<td><?php echo "$per"?></td>
</tr>
</table>
</html>

Output-:
Slip 22
Q.2 Write a menu driven PHP program to perform the following operations on associative arrays:

a) Sort the array by values (changing the keys) in ascending, descending order.

b) Also sort the array by values without changing the keys.

c) Filter the odd elements from an array.

d) Sort the different arrays at a glance using single function.

e) Merge the given arrays.

f) Find the Union, intersection& set difference of two arrays.

Solution
<html>
<body bgcolor="gold">

<?php
function is_odd($var)
{
if($var%2==1)
return $var;
}

$choice=$_POST['ch'];

$arr=array('a'=>1,'b'=>2,'c'=>3,'d'=>4,'e'=>5,'f'=>6,'g'=>7,'h'=>8);

$arr1=array('l'=>11,'m'=>22,'n'=>33,'o'=>44,'p'=>55,'q'=>66,'r'=>77,'s'=>88);

$arr2=array('a'=>10,'b'=>20,'c'=>30,'d'=>40,'e'=>50,'f'=>60,'g'=>70,'h'=>80);
switch($choice)
{
case 1:
sort($arr);
echo "Array in ascending order:<br>";
print_r($arr);
rsort($arr);
echo "<br>Array in descending order:<br>";
print_r($arr);
break;
case 2:
asort($arr);
echo "Array in ascending order:<br>";
print_r($arr);
arsort($arr);
echo "<br>Array in descending order:<br>";
print_r($arr);
break;
case 3:
print_r(array_filter($arr,'is_odd'));
break;
case 4:
array_multisort($arr,0,$arr1,1,$arr2,0);
print_r($arr);
echo "<br>";
print_r($arr1);
echo "<br>";
print_r($arr2);
echo "<br>";
break;
case 5:
print_r(array_merge($arr,$arr1));
break;
case 6:
print_r(array_intersect($arr,$arr1));
break;
case 7:
$union=array_merge($arr,$arr1);
print_r(array_unique($union));
break;
case 8:
print_r(array_diff($arr,$arr1));
break;
}

echo "<br><a href ='a2c2.html'> RETURN</a>";


?>
</font>
</body>
</html>
Output:-
Slip 23
C) Write a PHP script to create a form to accept customer information (name, address, ph-no). Once the
customer information is accepted, accept product information in the next form (Product name, qty,
rate). Display the bill for the customer in the next form. Bill should contain the customer information
and the information of the products entered.

Solution:

first.php

<html>

<body>

<form method ="post" action="second.php">

<table border="1">

<tr>

<td>customer Name:-</td>

<td><input type="text" name="name"></td>

</tr>

<tr>
<td>customer Phone Number:-</td>

<td><input type="text" name="ph-no"></td>

</tr>

<tr>

<td>customer address:-</td>

<td><input type="text" name="address"></td>

</tr>

<tr>

<td></td>

<td><input type="submit" value="save"></td>

</tr>

</table>

</form>
</body>

</html>

second.php

<html>

<body>

<?php

setCookie('name',$_POST["name"]);

setCookie('ph-no',$_POST["ph-no"]);

setCookie('address',$_POST["address"]);

echo"Hello".$_POST["name"]."!Enter Details....<br>";

?>

<form method ="post" action="third.php">


<table border="1">

<tr><td>Product name</td><td><input type="text" name="pname"></td></tr>

<tr><td>qty</td><td><input type="text" name="qty"></td></tr>

<tr><td>rate</td><td><input type="text" name="rate"></td></tr>

<tr><td></td><td><input type="submit" name="submit" value="DISPLAY"></td></tr>

</table>

</form>

</body>

</html>

third.php

<html>

<body>

<?php
echo "<b> customer Details</b><br>";

echo "<table border='1'>";

echo "<tr><td>";

echo"customerName:".$_COOKIE["name"]."<br>";

echo "</tr></td>";

echo "<tr><td>";

echo"customer phone:-".$_COOKIE["ph-no"]."<br>";

echo "</tr></td>";

echo "<tr><td>";

echo"Studcustomerent address:-".$_COOKIE["address"]."<br>";

echo "</tr></td>";

echo "<tr><td>";
echo "<b> customer Bill</b><br>";

echo "</tr></td>";

echo "<tr><td>";

echo"pname:".$_REQUEST["pname"];echo "</tr></td>";

echo "<tr><td>";

echo"qty:".$_REQUEST["qty"];echo "</tr></td>";

echo "<tr><td>";

echo"rate:".$_REQUEST["rate"];echo "</tr></td>";

echo "</table>";

if(isset($_POST['submit']))

$qty=(int)$_POST['qty'];

$rate=(int)$_POST['rate'];
$total = $qty*$rate;

echo"Total=".$total;

?>

</body>

</html>

Output-:
Slip 24
C) Write a PHP script to accept username and password. If in the first three chances,
username and password entered is correct, then display second form, otherwise
display error message.
Solution:

HTML file :

<html>
<head>
<script>
function getans()
{
st1=document.getElementById('txtname').value;
st2=document.getElementById('txtpass').value;
ob=new XMLHttpRequest();

ob.onreadystatechange=function()
{
if(ob.readyState==4 && ob.status==200)
{
if(ob.responseText==3)
{
alert("sorry you lost the chances to
login");
location="error.html";
}
else if(ob.responseText=="correct")
{
alert("you entered correct details");
}
else alert(ob.responseText);
}
}
ob.open("GET","slip8_Q2.php?n="+st1+"&p="+st2);
ob.send();
}
</script>
</head>
<body>
<input type=text id=txtname placeholder="username"></br>
<input type=password id=txtpass placeholder="password"></br>
<input type="button" onclick="getans()" value="Login">

</body>
</html>

HTML file : error.html

<html>
<body>
<h1>YOu lossed the chances of login</h1>
</body>
</html>

PHP file :
<?php
session_start();
$nm=$_GET['n'];
$ps=$_GET['p'];
if($nm==$ps)
{
echo "correct";
}
else if(isset($_SESSION['cnt']))
{
$x=$_SESSION['cnt'];
$x=$x+1;
$_SESSION['cnt']=$x;
echo $_SESSION['cnt'];

if($_SESSION['cnt']>=3)
$_SESSION['cnt']=1;
}
else
{
$_SESSION['cnt']=1;
echo "1";
}
?>

Output-:
Slip 25
C) Consider the following entities and their relationships Emp
(emp_no,emp_name,address,phone,salary) Salary(em_pno, Basic, HR, TA, DA) Dept
(dept_no,dept_name,location) Emp-Dept are related with one-many relationship
Create a RDB for the above and solve following Using above database. write a PHP
script which will print a salary statement for specified emp_no with his detail

Solution
<?php

$servername = "localhost";

$username = "username";

$password = "password";

$dbname = "your_database";

// Create connection

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

// Check connection

if ($conn->connect_error) {

die("Connection failed: " . $conn->connect_error);

$emp_no = $_GET['emp_no']; // You should handle the input securely to prevent SQL injection

$sql = "SELECT * FROM Emp INNER JOIN Salary ON Emp.emp_no = Salary.emp_no WHERE Emp.emp_no
= $emp_no";

$result = $conn->query($sql);

if ($result->num_rows > 0) {

// output data of each row


while($row = $result->fetch_assoc()) {

echo "Employee No: " . $row["emp_no"] . "<br>";

echo "Employee Name: " . $row["emp_name"] . "<br>";

echo "Address: " . $row["address"] . "<br>";

echo "Phone: " . $row["phone"] . "<br>";

echo "Basic Salary: " . $row["Basic"] . "<br>";

echo "HR Allowance: " . $row["HR"] . "<br>";

echo "TA Allowance: " . $row["TA"] . "<br>";

echo "DA Allowance: " . $row["DA"] . "<br>";

} else {

echo "0 results";

$conn->close();

?>

Output-:
Table:

yamlCopy code
| emp_no | emp_name | address | phone | salary |
|--------|----------|---------------|-------------|---------| | 1 | John | 123 Street | 1234567890 |
5000.00 | | 2 | Jane | 456 Avenue | 9876543210 | 6000.00 |

Salary Table:

yamlCopy code
| emp_no | Basic | HR | TA | DA | |--------|---------|--------|--------|--------| | 1 | 4000.00 |
500.00 | 300.00 | 200.00 | | 2 | 4500.00 | 600.00 | 400.00 | 300.00 |

Running the PHP script with emp_no=1 would produce the following output:

yamlCopy code
Employee No: 1 Employee Name: John Address: 123 Street Phone: 1234567890 Basic
Salary: 4000.00 HR Allowance: 500.00 TA Allowance: 300.00 DA Allowance: 200.00
Slip 26
C) Consider the following entities and their relationships Doctor (doc_no, doc_name,
address, city, area) Hospital (hosp_no, hosp_name, hosp_city) Doctor and Hospital
are related with many-many relationship. Create a RDB in 3 NF for the above and
solve following Using above database, write a PHP script which accepts hospital
name and print information about doctors visiting / working in that hospital in
tabular format.
Solution:

Html file :

<html>

<body>

<form action="slip_21.php" method="get">

Enter the Name Of Hospital : <input type=text name=hosp><br>

<input type=submit value=SUBMIT>

</form>

</body>

<html>

Php file :

<?php

$hosp=$_GET['hosp'];

$con=mysql_connect("localhost","root","");
$d=mysql_select_db("bca_programs",$con);

$q=mysql_query("select doctor.doc_no,doc_name,address,city,area from


doctor,hospital,doc_hosp where hosp_name='$hosp' and doc_hosp.doc_no=doctor.doc_no
and doc_hosp.hosp_no=hospital.hosp_no");

echo "<tr><td>Doctor no--</td><td>Doctor


Name--</td><td>Address--</td><td>city--</td><td>Area</td></tr>";

while($row=mysql_fetch_array($q))

echo "<br><tr><td>".$row[0]." | </td><td>".$row[1]." |


</td><td>".$row[2]." | </td><td>".$row[3]." |</td><td>".$row[4]." |</td></tr>";

mysql_close();

?>

Output-:
Slip 27
C) Considerer the following entities and their relationships project(pno integer,
p_name char(30), ptype char(20),duration integer), employee (eno integer, e_name
char (20), qualification char (15), joindate date) .The relationship between project -
employee: M-M, with descriptive attributes as start_date (date), no_of_hours_worked
(integer). Using above database write a script in PHP to accept a project name from
user and display information of employees working on the project.
Solution
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "your_database";

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

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

if (isset($_GET['project_name'])) {
$project_name = $_GET['project_name'];

// SQL query to retrieve employees working on the specified project


$sql = "SELECT e.eno, e.e_name, e.qualification, e.joindate, pe.start_date,
pe.no_of_hours_worked
FROM employee e
INNER JOIN project_employee pe ON e.eno = pe.eno
INNER JOIN project p ON p.pno = pe.pno
WHERE p.p_name = '$project_name'";

$result = $conn->query($sql);

if ($result->num_rows > 0) {
// Output data of each row
echo "<h2>Employees working on project $project_name:</h2>";
echo "<table border='1'>
<tr>
<th>Employee No</th>
<th>Employee Name</th>
<th>Qualification</th>
<th>Join Date</th>
<th>Start Date</th>
<th>No of Hours Worked</th>
</tr>";
while ($row = $result->fetch_assoc()) {
echo "<tr>";
echo "<td>" . $row['eno'] . "</td>";
echo "<td>" . $row['e_name'] . "</td>";
echo "<td>" . $row['qualification'] . "</td>";
echo "<td>" . $row['joindate'] . "</td>";
echo "<td>" . $row['start_date'] . "</td>";
echo "<td>" . $row['no_of_hours_worked'] . "</td>";
echo "</tr>";
}
echo "</table>";
} else {
echo "0 results";
}
}

$conn->close();
?>

<!DOCTYPE html>
<html>
<body>

<form action="script.php" method="get">


Project Name: <input type="text" name="project_name"><br>
<input type="submit" value="Submit">
</form>

</body>
</html>
Slip 28
C) Consider the following entities and their relationships student (sno integer,
s_name char(30), s_class char(10), s_addr char(50)), teacher (tno integer, t_name
char (20), qualification char (15),experience integer). The relationship between
student-teacher: m-m with descriptive attribute subject. Using above database write
a script in PHP to accept a teacher name from user and display the names of
students along with subjects to whom teacher is teaching.
Solution:

<html>

<body>

<form action="s28.php" method="POST">

<table border=1>

<tr>

<td>Enter teacher's name : </td>

<td> <input type="text" name="tname"></td>

</tr>

<tr><td></td><td><input type="submit" name="submit" value="Submit"></td></tr>

</form>

</body>

</html>
S28.php

<?php

$database="archana2";

$con =mysqli_connect("localhost","root" ,"");

if (!$con)

die('Could not connect: ' . mysqli_error());

mysqli_select_db ($con,"$database");

$tname=$_POST['tname'];

echo $query="select sname,subject from student,s_t,teacher where student.sno=s_t.sno


and teacher.tno=s_t.tno and tname='".$tname."'";

$result=mysqli_query($con,$query);
if(!$result)

die("An error occured...");

echo '<table>

<tr>

<th>Sname</th>

<th>Subject</th>

</tr>';

while($row=mysqli_fetch_array($result))

echo'

<tr>
<td>'.$row[0].'</td>

<td>'.$row[1].'</td>

</tr>';

echo '</table>';

mysqli_close($con);

?>
Output-:
Slip 29
C) Consider the following entities and their relationships Movie (movie_no,
movie_name, release_year) Actor (actor_no, name) Relationship between movie and
actor is many – many with attribute rate in Rs. Create a RDB in 3NF for the above
and solve following Using above database, write PHP scripts for the following:(Hint:
Create HTML form having three radio buttons) a) Accept actor name and display the
names of the movies in which he has acted. b) Insert new movie information. c)
Update the release year of a movie. (Accept the movie name from user)
Solution:

html file -
<html>

<body>

<form action="slip_22.php" method="get">

<h3>Enter Actor Name : <input type=text name=nm> </h3>

<input type=radio name=a value=1>Display Movie Name

<h3>Enter movie no :<input type=text name=m_no>

<h3>Enter movie name :<input type=text name=m_nm>

<h3>Enter release year :<input type=text name=r_yr>

<h3>Enter actor no :<input type=text name=a_no>

<h3>Enter actor name :<input type=text name=a_nm>

<input type=radio name=a value=2>Insert New movie info

<input type=submit value=OK>

</form>

<div id="place"></div>

</body>

</html>
php file -

<?php

$r = $_GET['a'];

$con = mysql_connect("localhost","root","");

$d = mysql_select_db("bca_programs",$con);

if($r == 1)

{ $actor_name = $_GET['nm'];

$q = mysql_query("select m_name from movie,actor,movie_actor where


movie.m_no=movie_actor.m_no and actor.a_no=movie_actor.a_no and
a_name='$actor_name'");

echo "

Movie Name

";

while($row=mysql_fetch_array($q))

echo $row[0]."

";

else if($r == 2)

{ $m_no = $_GET['m_no'];

$m_name = $_GET['m_nm'];
$r_yr = $_GET['r_yr'];

$a_no = $_GET['a_no'];

$a_name = $_GET['a_nm'];

$q = mysql_query("insert into movie values($m_no,'$m_name',$r_yr)");

$q1 = mysql_query("insert into actor values($a_no,'$a_name')");

echo "Value Inserted";

mysql_close();

?>

Output-:
Slip 30
C) Considerer the following entities and
their relationships Student
(Stud_id,name,class) Competition
(c_no,c_name,type) Relationship
between student and competition is
many-many with attribute rank and
year. Create a RDB in 3NF for the above
and solve the following. Using above
database write a script in PHP to accept
a competition name from user and
display information of student who has
secured 1st rank in that competition.
Solution:

Html file :

<html>

<body>

<form action="slip_13.php" method="get">

Enter the name of competition : <input type=text name=cname><br>

<input type=submit value=SUBMIT>

</form>

</body>

<html>
Php file :

<?php

$c_name = $_GET['cname'];

$con = mysql_connect("localhost","root","");

$d = mysql_select_db("bca_programs",$con);

$q = mysql_query("select student_slip_13.stud_id,stud_name,stud_class from


student_slip_13,compitition_slip_13,sc_slip_13 where
student_slip_13.stud_id=sc_slip_13.stud_id and sc_slip_13.c_no=compitition_slip_13.c_no
and c_name='$c_name' and rank=1");

echo "<table>";

echo "<tr><td>Student Id |</td><td>Student Name |</td><td>Student


Class</td></tr>";

while($row = mysql_fetch_array($q))

echo "<tr><td>".$row[0]."</td><td>".$row[1]."</td><td>".$row[2]."</td></tr>";

echo "</table>";

mysql_close();
?>

Output-:

You might also like