0% found this document useful (0 votes)
28 views149 pages

SameerShukla PHP Assignments PDF

This document contains PHP assignments for a student named Sameer Vardendu Shukla with roll number 11634. It includes multiple programming assignments involving PHP scripts and forms. Assignment 1 contains two parts - Part A1 involves designing a form to accept a string and count vowels, check palindrome; Part A2 involves designing a form to accept two strings and find occurrences of one string in another. Other assignments involve arithmetic operations on input numbers, comparing and manipulating input strings, and generating a product billing table from input details. The assignments demonstrate concepts like functions, arrays, operators, and regular expressions in PHP.

Uploaded by

Ashish
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)
28 views149 pages

SameerShukla PHP Assignments PDF

This document contains PHP assignments for a student named Sameer Vardendu Shukla with roll number 11634. It includes multiple programming assignments involving PHP scripts and forms. Assignment 1 contains two parts - Part A1 involves designing a form to accept a string and count vowels, check palindrome; Part A2 involves designing a form to accept two strings and find occurrences of one string in another. Other assignments involve arithmetic operations on input numbers, comparing and manipulating input strings, and generating a product billing table from input details. The assignments demonstrate concepts like functions, arrays, operators, and regular expressions in PHP.

Uploaded by

Ashish
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/ 149

Php Assignments

Name: Sameer Vardendu Shukla


Roll no: 11634

Assignment 1
Set A1
Q. 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’
constructor require stmt.) Program:

Php program=>

<?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 “Occurrence of
‘a’ : “.$vowels[‘a’].”<br>”;
Echo “Occurrence of ‘e’ : “.$vowels[‘e’].”<br>”;
Echo “Occurrence of ‘I’ : “.$vowels[‘I’].”<br>”;
Echo “Occurrence of ‘o’ : “.$vowels[‘o’].”<br>”; Echo
“Occurrence 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”;
}
?>

HTML file=>

<html>
<body>
<form method=”GET” action=”ass1a1.php”>
Enter the String : <input type=”text” name=”inputStr”><br>
<input type=”submit” name=”Submit”>
</form>
</body>
</html>
Output:
Set A2
Q. 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)

Program:

HTML file=>

<html>
<head><title>php program</title></head>
<body bgcolor=’#f1284e’ >
<form action=’ass1a2.php’ method=’post’>
<pre>
Enter1’ststring :<input type=’text’name=’str1’><br>

Enter2’ndstring :<input type=’text’name=’str2’><br>


Enter string to replacesmallstring :<input type=’text’
name=’str’><br>

<input type=’radio’ name=’ch’ value=1>first and last


occurrence<br>
<input type=’radio’ name=’ch’ value=2>total occurrence<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>

Php program=>

<?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=’a1a2.html’>go back</a></h1>
Set B1
Q. 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)

Program:
HTML FILE=>

<html>
<body bgcolor=pink >
<form action=”ass1b1.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>
<inputtype=submitvalue=ok> <input type=reset
value=clear> </form>

</body>

</html>
Php program:

<?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”;

}
?>
Set B2
Q. 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)Program:

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>Occurrence.


<input type=’radio’ name=”ch” value=2>Replace.
<input type=’radio’ name=”ch” value=3>split.
<inputtype=submitvalue=ok> <input type=reset
value=cancel>
</pre>
</form>
</body>

</html>

Php program=>
<?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 replacingstring::$str4<br>”;
Break;
Case 3:
Echo”After splitting the string::<br>”;
$s=preg_split(“//”,$str2);
Foreach($s as $v) echo “\t$v <br>”;
}
}

?>
Set C1
Q1. 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.) Program:
Php function:

<?php
$icode1=$_POST[“t1”];
$iname1=$_POST[“t2”];
$iunits1=$_POST[“t3”];
$irate1=$_POST[“t4”];
$icode=explode(“ “,$icode1);
$iname=explode(“ “,$iname1);
$iunits=explode(“ “,$iunits1);
$irate=explode(“ “,$irate1);
Echo”<center><Table border=2>
<tr>
<th>Item Code</th>
<th>Item Name</th>
<th>Units Sold</th>
<th>Item Rate</th>
<th>Total</th>
</tr>”;
For($i=0;$i<5;$i++)
{
{
Echo”<tr>
<td>$icode[$i]</td>
<td>$iname[$i]</td>
<td>$iunits[$i]</td>
<td>$irate[$i]</td>”;
$total=(int)$irate[$i]*(int)$iunits[$i];
Echo”<td>$total</td>
</tr>”;
}
Echo”</table></center>”;
?>

HTML FILE:
<html>
<head>
<title>Details of Items </title></head>
<body>
<center>
<form input method=”POST”
Action=”ass1setc1.php”> Item Code:-<input
Type=”text” name=”t1”><br><br> Item Name:-
<input type=”text” name=”t2”><br><br> Units Sold:-<input
type=”text” name=”t3”><br><br>

Rate:-<input type=”text” name=”t4”><br><br>


<input type=”submit” value=”submit”>
<input type=”reset” value=”reset”>
</form>
</center>
</body>
</html>

SetC2
Q.Write a PHP script for the following: Design a form toaccept
two strings. Compare the two strings using both methods (= =
operator & strcmp function). Append second string to thefirst
string. Accept the position from the user; from where the
characters from the first string are reversed. (Use radio buttons)
Program:
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.

<inputtype=”submit”value=”check”> <input
type=”reset”value=”cancel”>
</pre>
</form>
</body>

</html>

Php program=>

<?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;
}

?>
Assignment 2

Set A1
Q: 1) Write a menu driven program to perform the following
operations on an associative array:

a) Display the elements of an array along with thekeys.

b) Display the size of anarray

c) Delete an element from an array from the givenkey/index.


d) Reverse the order of each element’s key-value pair [Hint:use
array_flip()]
e) Traverse the elements in an array in random order [[Hint:use
shuffle()].
Program:

HTML file=>

<html>
<form action=’ass2a1.php’ method=’post’>
<pre> <h3>OPERATIONS</h3>
1<input type=’radio’ name=’a’ value=’1’>Display.<br>
2<input type=’radio’ name=’a’ value=’2’>size.<br>
3<input type=’radio’ name=’a’ value=’3’>delete.<br>
4<input type=’radio’ name=’a’ value=’4’>reverse.<br>
5<input type=’radio’ name=’a’ value=’5’>traverse.<br>
<inputtype=’submit’value=’ok’> <inputtype=’reset’
value=’cancel’><br>
</pre>
</form>
</body>
</html>

Php program=>

<?php

$array=array(‘zero’=>0,’one’=>1,’two’=>2,’three’=>3,’four’=>4,’
five’=>5);
$ch=$_POST[‘a’];
Switch($ch)
{
Case 1:foreach($array as $key=>$value)
{
Echo”key:$key val:$value.<br>”;
}break;
Case 2:echo sizeof($array);
Break;
Case 3:
$len=sizeof($array);
Array_splice($array,$len);
Print_r( $array);
Break;
Case 4:
Print_r(array_flip($array));
Break;
Case 5:

Shuffle($array);
Print_r($array);
Break;

?>
Set A2
Q. Accept a string from the user and check whether it is a
palindrome or not (Implement stack operations using array built-in
functions).
Program:

HTML File=>

<html>
<h3 > PALLINDROM </h3>
<form action=’ass1a2.php’ method=’post’>

Enter a string::<input type=’text’ name=str><br><br>

<inputtype=’submit’name=’OK’> <inputtype=’reset’
name=’CLEAR’>
</form>
</body>

</html>

Php program=>
<?php
$s=$_POST[‘str’];
$stack=array();
For($i=0;$i<strlen($s);$i++)
Array_push($stack,$s[$i]);
For($i=0;$i<strlen($s);$i++)
If(array_pop($stack)!=$s[$i])
Break;
If($i==strlen($s))
Echo “$s is pallindrome:”;
Else
Echo “$s is not pallindrom:”;

?>
Set B1
Q. Declare a Multidimensional Array. Display specific elementfrom
a Multidimensional array. Also delete given element from the
Multidimensional array.(After each operation display array
content [Hint : use print_r() ])

Program:

<html>
<body bgcolor=”gold”>
<?php
$stud=array(‘0’=>array(‘name’=> ‘deepak’ ,’age’=>20,’addr’=>’girim’),
‘1’=>array(‘name’=> ‘shankar’, ‘age’=>21,’addr’=>’khor’),
‘2’=>array(‘name’=> ‘ganesh’ , ‘age’=>19,’addr’=>’shirur’),
‘3’=>array(‘name’=> ‘radhu’ , ‘age’=>21,’addr’=>’khor’));
Print_r($stud);
Echo “<br>”;
Echo “<br> Element for delete is:”;
Echo “<br>stud[1][‘age’]<br>”;
Echo $stud[1][‘age’];
Echo “<br><br>”;
Unset($stud[1][‘age’]);
Print_r($stud);
?>
</body>
</html>
Set B2
Q. Define an array. Find the elements from the array that matches
the given value using appropriate search function.
Program:

HTML file=>
<html>
<head>
<meta http-equiv=”pragma” content=”no-cache”>
</head>
<body bgcolor=”gold”>
<form action=”ass2b2.php” method=”post”>

Enter Number :<br>


<input type=”text” name=’no’>
<br><br>
<inputtype=”submit”name=”SUBMIT”> <inputtype=’reset’
name=’CANCLE’>
</form>
<body>
</html>

Php program=>

<?php
$no=$_POST[‘no’];
If(empty($no))
{
Echo “Enter all data::”;
Echo “<br><a href=’a2b2.html’>Back</a>”;
}
Else
{
$arr=array(1,2,3,4,5,6,7,7,8,9,10);
Print_r($arr);
Echo “<br><br><br>”; If(in_array($no,
$arr))
Echo “$no occurred in array”;
Else

Echo “$no not occurred in array”;


}
?>
Set C1
Q. Write a menu driven program to perform the following stack
and queue related operations:[Hint: use Array_push(),Array_pop(),
Array_shift(), Array_unshift() ] a) Insert an element instack
b) Delete an element fromstack

c) Display the contents ofstack

d) Insert an element inqueue

e) Delete an element fromqueue

f) Display the contents ofqueue

Program:

HTML file=>
<html>
<body bgcolor=skyblue>
<form action=”ass2C1.php” method=”post”> Enter
choice :

<br><input type=”radio” name=”ch” value=1> Insert element in stack


<br>
<input type=”radio” name=”ch” value=2> Delete element from stack
<br>
<input type=”radio” name=”ch” value=3> Display content of stack
<br>
<input type=”radio” name=”ch” value=4> Insert element in
queue<br>
<input type=”radio” name=”ch” value=5> Delete element from queue
<br>
<input type=”radio” name=”ch” value=6> Display content of queue
<br>
<br>

<input type=”submit” value=”submit”>


<input type=”reset” value=”reset”>
</body>

</html>

Php program=>

<html>
<body bgcolor=”gold”> <?
$choice=$_POST[‘ch’];
{
$arr=array(1,2,3,4,5,6,7,8,9,10);
Switch($choice)
{
Case 1:
Array_push($arr,10);
Print_r($arr);
Break;
Case 2:

$ele=array_pop($arr);
Echo “Poped element : $ele”;
Break;
Case 3:

Print_r($arr);
Break;
Case 4:
Array_unshift($arr,”10”);
Print_r($arr);
Break;
Case5:
$ele=array_shift($arr);
Echo “Deleted element : $ele”;
Break;
Case6:

Print_r($arr);
Break;
}
}
Set C2
Q. Write a menu driven program to perform the following operations
on associative arrays:

a) Sort the array by values (changing the keys) inascending,


descendingorder.

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

c) Filter the odd elements from anarray.

d) Sort the different arrays at a glance using singlefunction.

e) Merge the givenarrays.

f) Find the intersection of twoarrays.


g) Find the union of twoarrays.
h) Find set difference of twoarrays.

Program:

HTML file=>
<html>

<body bgcolor=”skyred”>
<form action=”a2c2.php” method=”post”>
<h2>Enter choice :</h2>
<input type=”radio” name=”ch” value=1> Sort array by values in
ascending,descending order<br>
<input type=”radio” name=”ch” value=2> Sort array by values
without changing key values <br>
<input type=”radio” name=”ch” value=3> Filter odd elements from
array <br>
<input type=”radio” name=”ch” value=4> Sort different array at
glance using single function<br>
<input type=”radio” name=”ch” value=5> Merge given two arrays
<br>
<input type=”radio” name=”ch” value=6> Find intersection of two
array <br>
<input type=”radio” name=”ch” value=7> Find union of two array
<br>
<input type=”radio” name=”ch” value=8> Find set difference of two
array <br>
<br>

<input type=”submit” value=”SUBMIT”> <input type=”reset”


value=”CLEAR”>

</body>

</html>

Php program=>
<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;
Case3:
Print_r(array_filter($arr,’is_odd’));
Break;
Case4:

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;
Case7:
$union=array_merge($arr,$arr1);
Print_r(array_unique($union));
Break;
Case8:

Print_r(array_diff($arr,$arr1));
Break;
}

Echo “<br><a href =’a2c2.html’> RETURN</a>”;


?>
</font>
</body>
</html>
Assignment 3

Set A1
Q. Write a program to read two file names from user and append
contents of first file into second file.
Program:

HTML file=>

<html>
<body>
<form action=”a3a1.php” method=”POST”>
Enter First File:<input type=”text” name=”first”><br><br>
Enter Second File:<input type=”text” name=”second”><br><br>
<input type=”submit”>
</form>
</body>

</html>

Php program=>
<?php
$first=$_POST[‘first’];
$second=$_POST[‘second’]; If(!
file_exists($first))
{
Die(“<br>$first does not exist”);
}
If(!file_exists($second))
{
Die(“<br>$second does not exist”);
}
$fp1=fopen($first,’r’) or die(“unable to open first file”);
$fp2=fopen($second,’a’) or die(“unable to open second file”);
$data=fread($fp1,filesize($first));
Fwrite($fp2,$data);
Fclose($fp1);
Fclose($fp2);
Echo “<h2>Contents of first file is appanded to second file</h2>”;
?>
Set A2
Q. Write program to read directory name from user and display
content of the directory.

Program:

HTML file=>
<html>
<form action=”a3a2.php” method=”POST”>
<h1>Display directory contents</h1>
<br>
<h3>Enter directory name : <input type=”text” name=’d’></h3>
<pre>
<input type=”submit” name=”submit” value=”submit”>

</pre>
</form>

</body>
</html>

Php program=>

<?php

$d=$_POST[‘d’];
$h=dir(“.”);
If(is_dir($d))
{
$h=opendir($d);
Echo “<h3><B>Directory Contents”;
Echo “<br/>”;

While(($file=readdir($h))!==false)

{
Echo “<h3>$file<br/>”;
}

Closedir($h);
}
Else
{
Echo “<center><h2><center><u>Invalid Directory or
Directory does not exist!!!</u></center></h2></center>”;}
?>
Set B1
Q. Write a program to read a flat file “student.dat”, calculate the
percentage and display the data from file in tabular format.
(Student.dat file contains rollno, name, Syspro, TCS, CN, PHP,
JAVA, BA )

Program:

HTML File=>
<html><head><title>Exercise 3 Set B 1</title></head>
<body bgcolor=”green”>
<form action=”ass3b1.php” method=”POST”>
<h1>Reading flat file and display data in tabular form.</h1>
<br>
<br>
<hr>
<h3>Ente
r
directory
name(con
taining
file
student.d
at):<input
type=”tex
t”
name=’d’
></h3>

<pre>

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


<input type=”reset” name=”reset’” value=”reset”>

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

Php program=>

<?php
{
If (file_exists(‘student.dat’))

$f=fopen(‘student.dat’,’r’);

Echo “<br/><br/><br/>”;

Echo “<table border type=3 align=center>”;


Echo “<tr><td colspan=7 align=center><h3>Student
Records.</h3></td></tr>”;
Echo “<tr><td align=center>Rollno.</td>”;
Echo “<td align=center>Name.</td>”;
Echo “<tdalign=center>Electronics</td>”;
Echo “<td align=center>Computer.</td>”;
Echo “<td align=center>Maths</td>”;
Echo “<td align=center>Total.</td>”;
Echo “<td align=center>Percentage.</td></tr>”; While(!
feof($f))
{

$d= fgets($f);
$s=explode(‘ ‘,$d);

If(!empty($s[0]) && !empty($s[1]) && !empty($s[2]) &&


!empty($s[3]) && !empty($s[4]))
{

$m1=$s[2];
$m2=$s[3];
$m3=$s[4];
$total=$m1+$m2+$m3;
$p=($total/300)*100;
Echo “<tr><td align=center>$s[0]</td>”;
Echo “<td align=center>$s[1]</td>”;
Echo “<td align=center>$m1</td>”;
Echo “<td align=center>$m2</td>”;
Echo “<td align=center>$m3</td>”;
Echo “<td align=center>$total</td>”;
Echo “<td align=center>$p %</td></tr>”;
}
}
Echo “</table>”;
}

?>
Set B2

Q. Write a program to read directory name and extension.


Display the files with specified extension from that directory.

Program:
HTML file=>

<html>
<head><title>Exercise 3 Set A 1</title></head>
<body bgcolor=”grey”>
<form action=”a3b2.php” method=”POST”>
<center><h1><b><font type=”San Sarif”>Search file of given
extension.</font></b></h1></center>
<br>
<br>
<hr>
<h3>Ente
r
directory
name:
<input
type=”tex
t”
name=”d”
></h3>

<h3>Enter file extension: <input type=”text” name=”ex”></h3>

<pre>
<input type=”submit” name=”submit” value=”submit”>
<input type=”reset” name=”reset’” value=”reset”>

</pre>
</form>

</body>
</html>

Php program=>

<?php
$d=$_POST[‘d’];
$ext=$_POST[‘ex’];

If(is_dir($d))
{
$h=opendir($d);
Echo “<h3>The files with extension $ext in directory $d are: </h3>”;
While(($file=readdir($h))!==false)

If(is_dir($file))
{
Continue;
}
$e=explode(‘.’,$file);
If($e[1]==$ext)
{
Echo “<h3>$file</h3><br/>”;
}
}
Closedir($h);
}

?>

Assignment 4

Set A1
Q. Define an interface which has methods area( ), volume( ).
Define constant PI. Create a class cylinder which implements this
interface and calculate area and volume. (Hint: Use define(
))
Program:

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>Enterradius :<input type=’text’name=’rad’><br/></h3>


<h3>Enterheight :<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 program=>

<?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);

?>
Set A2
Q: 2) Write class declarations and member function definitions for
an employee(code, name, designation). Derive
emp_account(account_no, joining_date) from employee and
emp_sal(basic_pay, earnings, deduction) from emp_account. Write
a menu driven program

a) To build a mastertable

b) To sort allentries

c) To search anentry

d) Displaysalary

Program:

HTML file=>
<!DOCTYPE html>
<html lang=”en” dir=”ltr”>
<head>
<meta charset=”utf-8”>
<title></title>
</head>
<body>
<form class=”” action=”a4a2.php” method=”post”>
<input type=”radio” name=”rad” value=”1”>Build a Master Table
<br><br>
<input type=”radio” name=”rad” value=”2”>Sort all entries <br><br>
<input type=”radio” name=”rad” value=”3”>Search an entry by
Employee’s Name
<input type=”text” name=”ename”> <br><br>
<input type=”radio” name=”rad” value=”4”>Display Salary <br><br>
<input type=”submit” name=”sub” value=”Submit”>
</form>
</body>
</html>

Php program=>

<?php
Class employee
{
Public $code,$name,$desig;
Function construct($a,$b,$c)
{
$this->code=$a;

$this->name=$b;
$this->desig=$c;
}
Public function display_emp()
{
Echo’
<td>’.$this->code.’</td>
<td>’.$this->name.’</td>
<td>’.$this->desig.’</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 display_acc()
{
Echo’
<td>’.$this->ano.’</td>
<td>’.$this->jdate.’</td>
‘;
}
}
Class emp_sal extends emp_acc
{
Public $bpay,$earns,$ded,$total;
Function construct($a,$b,$c,$d,$e,$f,$g,$h)
{
Parent:: construct($a,$b,$c,$d,$e);$this->bpay=$f;
$this->earns=$g;
$this->ded=$h;
$this->total=$this->bpay + $this->earns - $this->ded;
}
Public function display_sal()
{
Echo’
<td>’.$this->bpay.’</td>
<td>’.$this->earns.’</td>
<td>’.$this->ded.’</td>
<td>’.$this->total.’</td>
‘;
}
}
$emp[0]=new
emp_sal(‘A923B’,’Ramesh’,’Staff’,’10001’,’21/09/2011’,’20000’
,’5000’,’3000’); $emp[1]=new
emp_sal(‘A823B’,’Ram’,’HR’,’10002’,’22/09/2011’,’25000’,’500
0’,’3000’);
$emp[2]=new
emp_sal(‘A723B’,’Sita’,’Analyst’,’10003’,’23/09/2011’,’22000’,’
5000’,’3000’);
$emp[3]=new
emp_sal(‘A623B’,’Gita’,’Organiser’,’10004’,’24/09/2011’,’21000
’,’5000’,’3000’);
$emp[4]=new
emp_sal(‘A523B’,’Aman’,’Manager’,’10005’,’25/09/2011’,’3000
0’,’5000’,’3000’);
$emp[5]=new
emp_sal(‘A423B’,’Amar’,’Staff’,’10006’,’26/09/2011’,’20000 ’,’ 5
000’,’3000’);
$emp[6]=new
emp_sal(‘A323B’,’Tarun’,’Analyst’,’10007’,’27/09/2011’,’21000’
,’5000’,’3000’);
$emp[7]=new
emp_sal(‘A223B’,’Mahi’,’Organiser’,’10008’,’28/09/2011’,’2100
0’,’5000’,’3000’);
$emp[8]=new emp_sal(‘A123B’,’Karna’,’Staff’,’10009
’,’29/09/2011’,’20000’,’5000’,’3000’); $emp[9]=new
emp_sal(‘A023B’,’Suraj’,’Staff’,’10010’,’30/09/2011’,’20000’,’50
00’,’3000’);
$ch=$_POST[‘rad’];
$ename=$_POST[‘ename’];
$flag=0;
Function mastertable($emp)
{
Echo ‘<table border=”1” width=”100%”>
<tr>
<th>Code</th>
<th>Name</th>
<th>Designation</th>
<th>Ac No</th>
<th>Joindate</th>
<th>BasicPay</th>
<th>Earnings</th>
<th>Deduction</th>
<th>Total Salary</th>
</tr>’;
For($i=0;$i<10;$i++)
{
Echo ‘<tr>’;
$emp[$i]->display_emp();
$emp[$i]->display_acc();
$emp[$i]->display_sal();
Echo ‘</tr>’;
}
Echo ‘</table>’;
}
Switch($ch)
{
Case 1:
Mastertable($emp);
Break;
Case 2: echo ‘Sorting w.r.t Employee Code <br><br>’;
Function srt($a,$b)
{
Return strcmp($a->code,$b->code);
}

Usort($emp,”srt”);
Mastertable($emp);
Break;
Case 3: echo “Searching for employee $ename…..<br><br>”;
For($i=0;$i<10;$i++)
{
$temp=$emp[$i]->getname();
If($temp==$ename)
{
$flag=1;
Break;
}
}
If($flag==0)
{
Echo “Not Found<br>”;
}
Else
{
Echo “Found in the records<br>”; }

Break;
Case 4: echo “Displaying Salary of all Employees …. <br><br>”;
Echo ‘<table border=”1” width=”100%”>
<tr>
<th>Employee Name</th>
<th>Basic Pay</th>
<th>Earnings</th>
<th>Deduction</th>
<th>Total Salary</th>
</tr>’;
For($i=0;$i<10;$i++)
{
Echo ‘<tr>
<td>’.$emp[$i]->getname().’</td>
‘;
$emp[$i]->display_sal();
}
Break;
}
?>

Set B1
Q:1) Create class rectangle and derive a class square from class
Rectangle. Create another 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 program to accept details of a square,
circle and rectangle and display the area.

Program:

HTML file=>
<!DOCTYPE html>
<html lang=”en” dir=”ltr”>
<head>
<meta charset=”utf-8”>
<title></title>
</head>

<body>
<form class=”” action=”a4b1.php” method=”post”>
<li>
Rectangle <br><br>
Length: <input type=”text” name=”len”> <br><br>
Width: <input type=”text” name=”width”> <br><br>
</li>
<li>
Square <br><br>
Side: <input type=”text” name=”side”> <br><br>
</li>
<li>
Circle <br><br>
Radius: <input type=”text” name=”radius”> <br><br>
</li>
<input type=”submit” name=”submit” value=”Submit”>
</form>
</body>
</html>
Php program=>
<?php
Define(“PI”,”3.142”);
Interface a
{
Function area();
}
Class rectangle implements a
{
Public $l,$b;
Function construct($x,$y)
{
$this->l=$x;
$this->b=$y;
}
Function area()
{
$area=$this->l * $this->b ;
Echo “Area of the Rectangle is $area <br>”;}
}
Class square extends rectangle implements a
{
Public $s;
Function construct($p,$q,$r)
{
Parent:: construct($p,$q);
$this->s=$r;
}
Function area()
{
Parent::area();
$area=$this->s * $this->s;
Echo “Area of the Square is $area <br>”;
}
}
Class circle implements a
{
Public $r;
Function construct($x)
{
$this->r=$x;
}
Function area()
{
$area=PI * $this->r * $this->r;
Echo “Area of the Circle is $area <br>”;
}
}
$side=$_POST[‘side’];
$length=$_POST[‘len’];
$width=$_POST[‘width’];
$radius=$_POST[‘radius’];
$obj=new square($length,$width,$side);
$obj1=new circle($radius);
$obj->area();
$obj1->area(); ?>
Set B2
Q:2) Create a class account(accno,cust_name). Derive two
classes from account as saving_acc(balance, min_amount)and
current_acc(balance,min_amount). a) Display amenu

b) SavingAccount

c) Current Account For each of this display a menu with the


following options.1.Create account 2. Deposit 3.Withdrawal

Program:

HTML file=>
<!DOCTYPEhtml>
<htmllang=”en”>
<head>
<meta charset=”UTF-8”>
<meta name=”viewport” content=”width=device-width,
initialscale=1.0”>
<title>Hierarchical Inheritance</title>
</head>
<body>
<form action=”ex4B_2.php” method=”post”>
<br> Enter Name : <input type=”text” name=”nm”>
<br> Enter Acc_no : <input type=”text” name=”a_n”>
<br> Account Type : <input type=”radio” name=”a_t” value=”1”>
Savings
<br> <input type=”radio” name=”a_t” value=”2”> Current
<br> Enter Bal : <input type=”text” name=”bal”>
<br> Enter Min Amt : <input type=”text” name=”m_a”>
<br> <input type=”radio” name=”op” value=”1”> Create account
<br> Enter Amt to Deposit : <input type=”text” name=”dep”>
<br> <input type=”radio” name=”op” value=”2”> Deposit
<br> Enter Amt to Withdraw : <input type=”text” name=”wit”>
<br> <input type=”radio” name=”op” value=”3”> Withdrawal
<br> <input type=”submit” value=”Submit”>
</form>
</body>
</html>
Php file=>

<?php
$a_t = $_POST[“a_t”];$nm
= $_POST[“nm”];

$a_n = $_POST[“a_n”];
$bal = $_POST[“bal”];
$m_a = $_POST[“m_a”];
$ch =$_POST[“op”];
$d =$_POST[“dep”];
$w = $_POST[“wit”];
Class acc
{
Public $accno;
Public $name;
Publicfunction construct($a,$n)
{
$this->accno = $a;
$this->name = $n;
}
}
Class saving_acc extends acc
{
Public $bal;
Public $min_amt;
Publicfunction construct($a_n, $nm, $b,$m)
{
Parent:: construct($a_n,$nm);
$this->bal = $b;
$this->min_amt = $m;
Echo “<br> Account created”;
}
Public function deposit($d)
{
$this->bal += $d;
Echo “<br> Balance : $this->bal”;
Echo “<br> deposited”;
}
Public function withdraw($w)
{
If($this->bal - $w < $this->min_amt)

{
Echo “<br> Amt cannot be withdrawed”;
}
Else
{
$this->bal -= $w;
Echo “<br> Balance : $this->bal”;
Echo “<br> withdrawned”;
}
}
}
Class current_acc extends acc
{
Public $bal;
Public $min_amt;
Publicfunction construct($a_n, $nm, $b,$m)
{
Parent:: construct($a_n,$nm);
$this->bal = $b;
$this->min_amt = $m;
Echo “<br> Accountcreated”;
}
Public functiondeposit($dep)
{
$this->bal += $dep;
Echo “<br> Balance : $this->bal “;
Echo “<br> deposited”;
}
Public function withdraw($w)
{
If($this->bal - $w < $this->min_amt)
{
Echo “<br> Amt cannot be withdrawed”;
}
Else
{
$this->bal -= $w;
Echo “<br> Balance : $this->bal “;
Echo “<br> withdrawned”;
}
}
}
If($a_t ==1)
{
$obj = new saving_acc($a_n, $nm, $bal,$m_a);
Switch($ch)
{
Case 1:
{
Echo “<br> Object created”;
}break; Case
2:

{
$obj->deposit($d);
}break;
Case3:
{
$obj->withdraw($w);
}break;

}
}
If($a_t ==2)
{
$obj = new current_acc($a_n, $nm, $bal,$m_a);
Switch($ch)
{
Case 1:
{
Echo “<br> Object created”;
}break;
Case2:
{
$obj->deposit($d);
}break; Case
3:

$obj->withdraw($w);
}break;

}
}

Set C1
Q:1) Define an interface for stack operation. Implement thisinterface
in aclass.

Program:
<?php

Interface stack_op
{

Function push($item);

Function pop();
Function top();
Function isEmpty();

Class stack implements stack_op

Public $stack,$limit;
Function construct($limit=10)

$this->stack=array();

$this->limit=$limit;
}

Public function push($item)

If(count($this->stack)<$this->limit){

Array_unshift($this->stack,$item);

Else
{
Die(“Stack Overflow!!”);

Public function pop()


{

If($this->isEmpty())

Die(“Stackisempty!!”); }

Else
{

Return array_shift($this->stack);

Public function top()

Return current($this->stack);
}
Public function isEmpty()

Return empty($this->stack);

}
}

$obj=newstack(); $obj->push(“ABC”);

$obj->push(“DEF”);

$obj->push(“GHI”);

$obj->push(“KLM”);
Echo $obj->top(); Echo “<br>”;

$obj->push(“NOP”);

Echo $obj->pop();

?>

Set C2
Q:2) Write necessary class and member function definitions for a
cricket player object. The program should accept details from
user (max :10) (player_code, name, runs, innings_played,
no_of_times_out). The program should contain following menu.
Enter details of players. Display average runs of a single player.
Average runs of all players. Display the list of players in sorted
order as per runs(use function overloading)

Program:

HTML FILE=>
<!DOCTYPEhtml>

<htmllang=”en”>

<head>

<meta charset=”UTF-8”>

<meta http-equiv=”X-UA-Compatible” content=”IE=edge”>

<meta name=”viewport” content=”width=device-width,


initialscale=1.0”>
<title>Document</title>

</head>

<body>
<form action=”ex4C_2.php” method=”post”>

<br> <input type=”radio” name=”ch” value=”1”> Enter details of


players

<br> <input type=”radio” name=”ch” value=”2”> Display average


runs of single player

<br> Enter name : <input type=”text” name=”nm”>

<br> <input type=”radio” name=”ch” value=”3”> Average runs of


all players
<br> <input type=”radio” name=”ch” value=”4”> Display list of all
players in sorted order as per runs

<br> <input type=”submit” value=”Submit”>

</form>
</body>

</html>

Php file=>
<?php

$ch = $_POST[“ch”];

$nm = $_POST[“nm”];
Class player
{

Public $code;

Public $name;

Public $runs;

Public $innings_played;

Public $no_times_out;

Public $avg_run;
Publicfunction construct($c, $nm, $r, $ip, $nto)

$this->code = $c;
$this->name = $nm;

$this->runs = $r;

$this->innings_played = $ip;

$this->no_times_out = $nto;

Public function avg_runs($player)

{
$player->avg_run = $player->runs / ($player->innings_played -
$player->no_times_out);

Echo ‘<table border=”1” width=”100%”>


<tr>

<th>Name</th>

<th>Avg_runs</th>

</tr>’;

Echo “<tr>”;

Echo “<td>”.$player->name.”</td>”;

Echo “<td>”.$player->avg_run.”</td>”;
Echo “</table>”;
}
}

Function display($player)

Echo ‘<table border=”1” width=”100%”>

<tr>

<th>Code</th>

<th>Name</th>
<th>Runs</th>
<th>Innings_played</th> <th>No_times_out</th>

</tr>’;

For($i=0;$i<10;$i++)

Echo ‘<tr>’;

Echo “<td>”.$player[$i]->code.”</td>”;

Echo “<td>”.$player[$i]->name.”</td>”;

Echo “<td>”.$player[$i]->runs.”</td>”;

Echo “<td>”.$player[$i]->innings_played.”</td>”; Echo


“<td>”.$player[$i]->no_times_out.”</td>”;
Echo ‘</tr>’;

Echo ‘</table>’;
}

$player[0] = new player(“1”, “Abc”, 200, 5, 3);

$player[1] = new player(“2”, “Def”, 300, 6,4);

$player[2] = new player(“3”, “Ghi”, 250, 5,3);

$player[3] = new player(“4”, “Jkl”, 400, 7, 4);

$player[4] = new player(“5”, “Mno”, 350, 6, 5); $player[5] = new


player(“6”, “Pqr”, 450, 7,3); $player[6] = new player(“7”, “Stu”, 275,3,
1);
$player[7] = new player(“8”, “Vwx”, 375, 4, 2);

$player[8] = new player(“9”, “Xyz”, 325, 5, 3);

$player[9] = new player(“10”, “Aaa”, 500, 7, 4);

Switch ($ch)

Case ‘1’:

{
Echo “Details of each player”;
Display($player);

}
Break;

Case ‘2’:

Echo “Average runs of single player”;

For ($i=0; $i <10 ; $i++)

{
If(strcmp($player[$i]->name,$nm) == 0)
$player[$i]>avg_runs($player[$i]);

}
}

Break;

Case ‘3’:

Echo “Average runs of all players”;

For ($i=0; $i <10 ; $i++)


{ $player[$i]->avg_runs($player[$i]);

}
Break;

Case ‘4’:

Echo “List of players in sorted order as per runs”;

$p = new player(1, “a”, 10, 2, 1);

For ($i = 0; $i < 10; $i++)


{

For ($j = $i + 1; $j < 10; $j++)

{
If($player[$i]->runs > $player[$j]->runs)

$p = $player[$i];

$player[$i] = $player[$j];

$player[$j] = $p;

}
}

Display($player);

}
Break;

Assignment 5

Set A1
Program:
HTML file:

<html>
<body>
<form action=”a5a1.php” method=”POST”>
Enter Department name : <input type=”text” name=”dept_name”
/></br>
<input type=”submit”/>
</form>
</body>
</html>

Phpfile:

<?php

$dept_name = $_POST[‘dept_name’];

$con = pg_connect( “dbname=test” );


If( !$con ) {
Echo ‘Connection not established’;
Exit;
}

$dept_insert = “insert into dept values(1,’HR’,’1stFloor’) ,(2, ‘Comp


sci’, ‘2ndfloor’),(3,’Maths’,’2nd

Floor’),(4,’Electronics’,’3rdFloor’)”;

$res = pg_query($con,$dept_insert);
$emp_insert = “insert into employee values( 1,
‘abc’,’Pune’,’7894356’,’20000’,1),( 2,
‘abc’,’Pune’,’7894356’,’10000’, 1),( 3,
‘abc’,’Pune’,’7894356’,’30000’,3),( 4,
‘abc’,’Pune’,’7894356’,’120000’,2)”;

$res1 = pg_query($con,$emp_insert);

$strQuery = “select max(salary), min(salary), sum(salary) from


employee where d_no in(select d_no from dept where
Dname = ‘$dept_name’)”;

$result = pg_query($con,$strQuery);

$row = pg_fetch_row($result);

?>
<html>
<body> <table>
<tr>
<th>Maximum salary</th>
<th>Minimum salary</th>
<th>Sum</th>
</tr>
<tr>
<td><?php echo $row[0];?></td>
<td><?php echo $row[1];?></td> <td><?php
echo $row[2];?></td>

</tr>
</table> </body>

</html>

Set A2
Program:
HTML file:

<html>
<center>
<form method=GET action=a5a2.php>
Hospital Name : <input type=text name=hname>
<input type=submit value=Submit>
</form>
</center>
</html>

Php program=>

<?php

$hname = $_GET[‘hname’];

$db = pg_connect(“host=localhost dbname=Slips user=hp password=


“);
If($db)
{
$query = “select * from doc where dno in(select dno from doc_hosp
where hno in(select hno from hosp where
Hname=’$hname’))”;
$resultSet = pg_query($db,$query);
Echo “<h1>Doctor from hospital $hname are…</h1>”;
Echo “<table style=height:400;width:400; border=3>”;
Echo “<tr><th>Dno</th>”;
Echo “<th>Name</th>”;
Echo “<th>Address</th>”;
Echo “<th>City</th></tr>”;
While(($row = pg_fetch_array($resultSet)) != null)
{
Echo “<tr><td>”.$row[‘dno’].”</td>”;
Echo “<td>”.$row[‘dname’].”</td>”;
Echo “<td>”.$row[‘addr’].”</td>”;
Echo “<td>”.$row[‘city’].”</td></tr>”;
}
Echo “</table>”;
}
?>
Set B1
Q: 1) 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.

Program:
HTML file:

<html>

<head>

<title>
A5SETAB1
</title>

</head>

<body>

<form action=”a5b1.php” method=”POST”>

Enter the Project name : <input type=”text” name=”pname”>


<br><br>

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

</form>

</body>
</html>
Php file:
<?php
$pname=$_POST[‘pname’];

$db=pg_connect(“host=localhost user=test_user dbname=tybcs01”);

If(!$db)

Die(“An error occurred…”);

Else

Echo “Successfully connected to the database <br><br>”;


$query=”select * from employee where emp_no in(select emp_no
from

E_p where p_no in(select p_no from projetc where pname=’”.


$pname.”’))”;

$result=pg_query($query); If(!

$result)

Die(“An error occurred…”);

Echo ‘<table>

<tr>
<th>Eno</th>

<th>Ename</th>

<th>JoinDate</th> <th>Qualifications</th>

</tr>’;

While($row=pg_fetch_row($result))

{
Echo ‘<table>

<tr>

<td>’.$row[0].’</td>
<td>’.$row[1].’</td>

<td>’.$row[2].’</td> <td>’.$row[3].’</td>

</tr>’;

}
Pg_close($db);

?>
Set B2
Q: 2) 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 betweenstudentteacher:
m-m with descriptive attributesubject.
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

Program:
HTMLfile

<html>

<head>
<title>

A5SETAB2

</title>
</head>

<body>

<form action=”a5b2.php” method=”POST”>

Enter teacher’s name : <input type=”text” name=”tname”>

<br><br>

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

</form>
</body>

</html>

Phpfile:
<?php

$tname=$_POST[‘tname’]; $db=pg_connect(“host=localhost
user=test_userdbname=tybcs01”);

If(!$db)

Die(“An error occurred…”);

Else

Echo “Successfully connected to the database <br><br>”;


$query=”select sname,subject from student,s_t where sno in(select
Sno from s_t where tno in(select tno from teacher where

Tname=’”.$tname.”’))”;

$result=pg_query($query);

If(!$result)

{
Die(“An error occurred…”);

Echo ‘<table>

<tr>
<th>Sname</th>

<th>Subject</th>

</tr>’;

While($row=pg_fetch_row($result))

Echo’
<tr>

<td>’.$row[0].’</td>

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

</tr>’;
}
Echo ‘</table>’;

Pg_close($db);

?>

Set C1
Q: 1) 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 3 NF 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 moviesin
which he hasacted.

b) Insert new movie information.


c) Update the release year of a movie. (Accept the movie namefrom
user)

Program:
HTML File

<html>

<head>

<title>

A5SETC1

</title>

</head>

<body>
<formaction=”a5c1.php”method=”POST”> <input type=”radio”
name=”rad”value=”1”>

Enter Actor Name : <input type=”text” name=”aname”>

<br><br><br>

<input type=”radio” name=”rad” value=”2”>

Enter Movie Information: <br><br>

Movie name : <input type=”text” name=”mname”> <br> <br>

Release Year : <input type=”text” name=”ryear”> <br><br>

<br>

<input type=”radio” name=”rad” value=”3”>


Update Movie Release Year <br><br>

Enter Moive Name: <input type=”text” name=”mname”>

<br><br>

Enter updated year: <input type=”text” name=”ryear”>

<br><br>

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

</form>

</body>

</html>
Php file:
<?php

//Assuming all relations exist in the database

$db=pg_connect(“host=localhost user=test_user dbname=tybcs01”);

If(!$db)
{

Die(“An error occurred…”);

Else
{
Echo “Successfully connected to the database <br><br>”;

$ch=$_POST[‘rad’];

Switch($ch)

Case ‘1’: $aname=$_POST[‘aname’];


$query=”select movie_name from movie where

Movie_no in(select movie_no from movie_actor where act_no


in(select

Act_no from actor where act_name=’”.$aname.”’))”;

$result=pg_query($query);

If(!$result)
{

Echo “Some error occurred";

break;

}
While($row=pg_fetch_row($result))
{

Echo ‘’.$row[0].’’;

Echo “<br>”;

}
Break;
Case ‘2’: $mname=$_POST[‘mname’];

$ryear=$_POST[‘ryear’];

$query=”insert into movie values(DEFAULT,

‘”.$mname.”’, ‘”.$ryear.”’)”; $result=pg_query($query);

If(!$result)

Echo “Some error occurred”;

Break;

}
Echo “Inserted new record successfully <br><br>”;

Break;

Case ‘3’: $mname=$_POST[‘mname’];

$ryear=$_POST[‘ryear’];
$query=”update table movie set ryear=’”.$ryear.”’

Where mname=’”.$mname.”’”;

$result=pg_query($query);

If(!$result)
{

Echo “Some error occurred”;

Break;
}

Echo “Updated information successfully”;

Break;
}

Pg_close($db);

?>

Set C2
Q: 2) 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 andsolve
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 1 st rank in thatcompetition

Program:
HTMLfile

<html>

<head>

<title>

A5SETC2

</title>

</head>
<body>

<form action=”a5c2.php” method=”POST”>

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


<br><br>

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

</form>

</body>

</html>

Phpfile:
<?php

$db=pg_connect(“host=localhost user=test_user dbname=tybcs01”);

If(!$db)
{
Die(“An error occurred…”);

Else

Echo “Successfully connected to the database <br><br>”;

$cname=$_POST[‘cname’];

$query=”select * from student where stud_id in(select stud_id from


Student_competetion where rank=1 and c_no in(select c_no from
competetion

Where c_name=’”.$cname.”’))”;
$result=pg_query($query);

If(!$result)

Die(“Some error occurred”);

While($row=pg_fetch_row($result))

{
Echo ‘’.$row[0].’ <br>’; //id

Echo ‘’.$row[1].’ <br>’; //name

Echo ‘’.$row[2].’ <br>’; //class


}

Pg_close($db);

?>

You might also like