php slip 16
php slip 16
CERTIFICATE
--------------------------- -----------------------------
Signature of Examiner Signature of Examiner
(External) (internal)
--------------------- ----------------------
(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
ANS=
S1.html
<html>
<body>
</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);
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'];
$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
?>
</body>
</html>
Output
samruddhi
Enter the String :
Submitquery
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 :
total occurence
replace
OK Cancel
string1:: ram
string2:: patil
string for replace:: seeta
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>
<pre>
</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>";
if(strlen($str1)>strlen($str2))
switch($ch)
case 1: $pos=strpos($str1,$str2);
if($pos!=0)
else
break;
case 2:
$str4=str_replace($str2,$str3,$str1);
echo $str4;
break;
case 3: $s=preg_split("//",$str1);
break;
else
switch($ch)
case 1:$pos=strpos($str2,$str1);
if($pos!=0)
else
break;
case 2: $str4=str_replace($str1,$str3,$str2);
break;
case 3:
$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 {
</style>
</head>
<body>
</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 "<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 "</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>
<pre>
</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'];
switch($ch)
case 1:
if($str1==$str2)
else
break;
case 2:
if($str1===$str2)
else
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);
?>
Output-:
slip 7
Q.1 Write a menu driven PHP program to perform the following operations on an
associative array:
iv. Reverse the order of each element’s key-value pair.[Hint: use array_flip()]
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 "3. Delete an element from an array from the given index.\n";
$choice = trim(fgets(STDIN));
switch($choice) {
case 1:
foreach($assoc_array as $key => $value) {
break;
case 2:
break;
case 3:
$key = trim(fgets(STDIN));
if(array_key_exists($key, $assoc_array)) {
unset($assoc_array[$key]);
} else {
break;
case 4:
$assoc_array = array_flip($assoc_array);
break;
case 5:
$keys = array_keys($assoc_array);
shuffle($keys);
foreach($keys as $key) {
break;
case 6:
exit(0);
default:
?>
OUTPUT
1. Display the elements of an array along with the keys.
6. Exit.
Size of array: 3
Element deleted.
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.
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;
}
<head><title>A4A1</title></head>
<br/>
<hr>
<br/>
<br/>
</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);
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);
$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>
<pre>
<h1>Circle:</h1>
<h1>
square:</h1>
<h1>
Rectangle:
</h1>
</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);
function area($c,$d)
{
$area=$c*$d;
echo"Area of rectangle......:".$area;
echo"<br><BR>";
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>";
?>
</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>
<select id="saving">
<option value="create">Create</option>
<option value="deposite">Deposit</option>
<option value="withderw">Withderw</option>
</select>
</form>
</body>
</html>
slip12.php
<!DOCTYPE html>
<html>
<body>
<?php
class Account {
public $acc_no;
public $acc_name;
$this->acc_name = $acc_name;
$this->acc_no = $acc_no;
}
class saveing_acc extends Account {
public $blance;
public $min_amount;
$this->acc_name = $acc_name;
$this->acc_no = $acc_no;
$this->blance = $blance;
$this->min_amount = $min_amount;
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>";
public $min_amt;
$this->acc_name = $acc_name;
$this->acc_no = $acc_no;
$this->blan = $blan;
$this->min_amount = $min_amount;
echo "<td>{$this->acc_no}</td>" ;
echo "<td>{$this->blan}</td>";
echo"</table>";
$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>
<br/>
</form>
</center>
</body>
<html>
slip13.php
<?php
$distance=$_POST['distance'];
$units=$_POST['units'];
if($units=='kms'){
$miles=$distance/1.60934;
}else{
$kms=$distance*1.60934;
?>
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
$email = "[email protected]";
$pattern = '/^(?![\d._@])[\w.]+@[a-zA-Z_]+?\.[a-zA-Z]{2,3}$/';
if (preg_match($pattern, $email)) {
} else {
?>
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>
</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){
exit;
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['Quntity']."</td>";
echo "<td>".$row['Rate']."</td>";
echo "<td>".$row['Amount']."</td></tr>";
}
echo "</table>";
?>
INSERT INTO `bill` (`s.no`, `Name Item`, `Quntity`, `Rate`, `Amount`) VALUES
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>
</head>
<?php
if (isset($_POST['unit-submit'])) {
$units = $_POST['units'];
if (!empty($units)) {
$result = calculate_bill($units);
/**
*/
function calculate_bill($units) {
$unit_cost_first = 3.50;
$unit_cost_second = 4.00;
$unit_cost_third = 5.20;
$unit_cost_fourth = 6.50;
$temp = 50 * $unit_cost_first;
else {
?>
<body>
<div id="page-wrap">
<h1>Php - Calculate Electricity Bill</h1>
</form>
<div>
</div>
</div>
</body>
</html>
OUTPUT-:
Solution-:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["name"])) {
} else {
$name = test_input($_POST["name"]);
if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
}
if (empty($_POST["course"])) {
} else {
$course = test_input($_POST["course"]);
if (empty($_POST["mobile"])) {
} else {
$mobile = test_input($_POST["mobile"]);
if (!preg_match("/^[0-9]{10}$/",$mobile)) {
function test_input($data) {
$data = trim($data);
$data = htmlspecialchars($data);
return $data;
?>
<br><br>
Course: <input type="text" name="course">
<br><br>
<br><br>
</form>
<?php
?>
</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);
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>
var i = 0;
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
return null;
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
function amt()
{
if(count == null)
SetCookie('count','1')
return 1
else
DeleteCookie('count')
SetCookie('count',newcount,exp)
return count
function getCookieVal(offset)
if (endstr == -1)
endstr = document.cookie.length;
</SCRIPT>
<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>
<center>
</center>
</form>
</body>
</html>
2.php-
<?php
color is ".$_GET['c']."
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 "</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>
</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.
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;
}
Solution:
first.php
<html>
<body>
<table border="1">
<tr>
<td>customer Name:-</td>
</tr>
<tr>
<td>customer Phone Number:-</td>
</tr>
<tr>
<td>customer address:-</td>
</tr>
<tr>
<td></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>";
?>
</table>
</form>
</body>
</html>
third.php
<html>
<body>
<?php
echo "<b> customer Details</b><br>";
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>
<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
// Check connection
if ($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) {
} else {
$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>
</body>
<html>
Php file :
<?php
$hosp=$_GET['hosp'];
$con=mysql_connect("localhost","root","");
$d=mysql_select_db("bca_programs",$con);
while($row=mysql_fetch_array($q))
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'];
$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>
</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>
<table border=1>
<tr>
</tr>
</form>
</body>
</html>
S28.php
<?php
$database="archana2";
if (!$con)
mysqli_select_db ($con,"$database");
$tname=$_POST['tname'];
$result=mysqli_query($con,$query);
if(!$result)
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>
<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'];
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'];
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>
</body>
<html>
Php file :
<?php
$c_name = $_GET['cname'];
$con = mysql_connect("localhost","root","");
$d = mysql_select_db("bca_programs",$con);
echo "<table>";
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-: