Download as pdf or txt
Download as pdf or txt
You are on page 1of 71

Guru Gobind Singh Indraprastha University

Sector -16 C, Dwarka, Delhi, India

Practical- PHP Lab


BCA-313
By
Name: Mehak
Enrollment No: 02016702018

Under the guidance:

Dr. ANUKOOL BAJPAI


Principal

Sirifort Institute of Management Studies


Plot No.8, Institutional Area Rohini Sector-25, New Delhi 110085.
PHP Practical File BCA V Sem(morning)

QUE .1- WAP to print Welcome message along with your name.

<html>

<head>

<title>hello message</title>

</head>

<body>

<form action="" method="get">

Your name <br>

<input type="text" name="name" required > <br>

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

</form>

<br><br>

Mehak(02016702018)

</body>

</html>

<?php

if(isset($_GET['sub']))

$a = $_GET['name'];

echo"welcome $a" ;

?>

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

OUTPUT :

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

QUE .2- WAP to calculate simple interest, input enter by the user.
<html>

<head>

<title>simple interest</title>

</head>

<body>

Mehak(02016702018) <BR><BR>

<form action="" method="get">

Principle Amount <br>

<input type="number" name="p" required > <br><br>

Rate <br>

<input type="number" placehoder="in %age" name="r" required > <br><br>

Time in years <br>

<input type="number" name="t" required > <br><br>

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

</form>

</body>

</html>

<?php

if(isset($_GET['sub']))

$principle = $_GET['p'];

$rate = $_GET['r'];

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

$time = $_GET['t'];

$SI = ($principle * $time * $rate) / 100;

echo "Simple Interest = ". $SI;

?>

OUTPUT :

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

QUE .3- WAP to calculate area of a rectangle, input enter by the user.
<html>

<head>

<title> Area of a rectangle</title>

</head>

<body>

Mehak(02016702018)

<br><br>

<form action="" method="get">

length <br>

<input type="text" name="len" > <br>

breadth<br>

<input type="text" name="bre" > <br>

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

</form>

</body>

</html>

<?php

if(isset($_GET['sub']))

$a = $_GET['len'];

$b = $_GET['bre'];

$c = $a * $b ;

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

echo $c;

?>

OUTPUT :

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

QUE .4- WAP to calculate the parameter of a circle, input enter by the
user.
<html>

<head>

<title> Perimeter of a circles</title>

</head>

<body>

Mehak(02016702018)

<BR><BR>

<form action="" method="get">

radius <br>

<input type="text" name="rad" > <br>

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

</form>

</body>

</html>

<?php

if(isset($_GET['sub']))

$a = $_GET['rad'];

$c = $a * 3.14*2;

echo $c;

?>

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

OUTPUT :

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

QUE .5- WAP to convert the temperature into ˚F to ˚C, input enter by
the user.
<html>

<head>

<title>fahrenheit to celcius</title>

</head>

<body>

Mehak(02016702018)<BR><br>

<form action="" method="get">

Temperature in fahrenheit<br>

<input type="text" name="fah" required > <br>

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

</form>

</body>

</html>

<?php

if(isset($_GET['sub']))

$a = $_GET['fah'];

$b=($a-32)*5/9;

echo" $a degree fahrenheit is equals to $b degree celcius" ;

?>

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

OUTPUT :

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

QUE .6- WAP to check the number whether it is prime or not, input
enters by the user.
<html>

<head>

<title>Prime number or not </title>

</head>

<body>

Mehak(02016702018) <br><BR>

<form method="post">

Enter The Number:<br>

<input type="number" name="n"/ > <br>

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

</form>

</body>

</html>

<?php

if($_POST)

$n = $_POST['n'];

for($i=2;$i<=$n-1;$i++)

if($n%$i==0){

$value=True;

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

if(isset($value) && $value){

echo 'The number '.$n.' is not a Prime number';

else{

echo 'The number '.$n.' is a Prime number';

}}

?>

OUTPUT :

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

QUE .7- WAP to print the odd number series, input enter by the user.
<html>

<head>

<title> odd series</title>

</head>

<body>

Mehak(02016702018)<BR><br>

<form action="" method="get">

length of series <br>

<input type="text" name="len" > <br>

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

</form>

</body>

</html>

<?php

if(isset($_GET['sub']))

$a = $_GET['len'];

$n = 2;

$i = $a * $n;

for($j=1; $j<$i; $j+=2)

echo "$j".",";

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

?>

OUTPUT :

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

QUE .8- WAP to generate the odd & even number series, the range
input by the user.
<html>

<head>

<title> odd and even series</title>

</head>

<body>

Mehak(02016702018) <BR><BR>

<form action="" method="get">

length of series <br>

<input type="text" name="len" > <br>

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

</form>

</body>

</html>

<?php

if(isset($_GET['sub']))

$a = $_GET['len'];

$n = 2;

$i = $a * $n;

echo"Odd series :- ";

for($j=1; $j<$i; $j+=2)

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

echo "$j".", ";

echo"<br>";

echo"even series :- ";

for($j=2; $j<=$i; $j+=2)

echo "$j".", ";

} }

?>

OUTPUT :

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

QUE .9- WAP to generate the series which divisible by 9, the range
input by the user.
<html>

<head>

<title> divisibles of nine</title>

</head>

<body>

Mehak(02016702018) <BR><BR>

<form action="" method="get">

length of series <br>

<input type="text" name="len" > <br>

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

</form>

</body>

</html>

<?php

if(isset($_GET['sub']))

$a = $_GET['len'];

$n = 9;

$i = $a * $n;

for($j=9; $j<=$i; $j+=9)

echo "$j".",";

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

?>

OUTPUT :

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

QUE .10- WAP to check the number whether it is Armstrong or not,


number input by the user.
<html>

<head>

<title>armstrong</title>

</head>

<body>

Mehak(02016702018)<br><br>

<form action="" method="get">

enter number<br>

<input type="text" name="num" required > <br>

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

</form>

</body>

</html>

<?php

function arms($number)

{ $sum= 0;

$x= $number;

while($x!=0)

{ $rem= $x % 10;

$sum= $sum + $rem*$rem*$rem;

$x= $x/10; }

if($number==$sum)

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

return 1;

else

return 0; }

if(isset($_GET['sub'])){

$number=$_GET['num'];

$flag= arms($number);

if($flag==1)

{ echo"Yes, $number is an Armstrong Number"; }

Else

{ echo"No, $number is not an Armstrong Number";} }

?>

OUTPUT :

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

QUE .11- WAP to find the factorial of a number, input enter by the
user.
<html>

<head>

<title>factorial</title>

</head>

<body>

Mehak(02016702018) <br><BR>

<form action="" method="get">

Enter the number<br>

<input type="number" name="n" required > <br>

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

</form>

</body>

</html>

<?php

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

$fact=1;

$n=$_GET['n'];

echo"Factorial of $n is = <BR><BR>";

for($i=1;$i<=$n;$i++){

$fact=$fact*$i;

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

echo $fact. "<br>";}

?>

OUTPUT :

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

QUE .12-WAP to calculate the electricity bill on the basis of define


slab:-
If consumed units between 1-100 then @Rs. 1 per unit
Else If consumed units between 101-200 then @Rs. 2 per unit
Else If consumed units between 201-300 then @Rs. 4 per unit
Else If consumed units between 301-400 then @Rs. 5 per unit
Else If consumed units between 401-500 then @Rs. 6 per unit
Else If consumed units more than 500 then @Rs. 10 per unit
Inputs entered by the user like Previous Meter Reading, Current Meter
Reading. Output will be display like Previous Meter Reading, Current
Meter Reading, Total Consumed Units, Total Bill Amount.
<html>

<head>

<title>electricity </title>

</head>

<body>

Mehak(02016702018)<br><br>

<form action="" method="get">

Previous reading <br>

<input type="number" name="pre" required > <br><br>

Current reading <br>

<input type="number" name="cur" required > <br><br>

<input type="submit" name="sub" value="calculate bill">

</form>

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

</body>

</html>

<?php

if(isset($_GET['sub']))

$prev = $_GET['pre'];

$cur = $_GET['cur'];

$bill = '';

$consumed = $cur - $prev;

if($consumed<=100 && $consumed>=0)

{$bill = $consumed * 1; }

elseif($consumed<=200 && $consumed>100)

{ $bill = $consumed * 2;}

elseif($consumed<=300 && $consumed>200)

{ $bill = $consumed * 4;}

elseif($consumed<=400 && $consumed>300)

{ $bill = $consumed * 5;}

elseif($consumed<=500 && $consumed>400)

{ $bill = $consumed * 6;}

elseif($consumed>500)

{ $bill = $consumed * 10;}

else

{echo"invalid value";}

echo"previous reading = $prev <br>";

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

echo"current reading = $cur <br>";

echo"units consumed = $consumed <br>";

echo"your bill is rupees $bill";

?>

OUTPUT :

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

QUE .13- WAP to print the fabonnaci series, input range entered by
the user.
<html>

<head>

<title>fabonacci</title>

</head>

<body>

Mehak(02016702018)<BR><BR>

<form action="" method="get">

enter number<br>

<input type="text" name="num" required > <br>

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

</form>

</body>

</html>

<?php

if($_GET)

function Fibonacci($n)

$num1= 0;

$num2= 1;

$counter= 0; while($counter < $n)

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)
echo ' '.$num1;

$num3= $num2 + $num1;

$num1= $num2;

$num2= $num3;

$counter= $counter+1;

//for a pre defined number for Fibonacci.

$number = $_GET['num'];

$n = $number; Fibonacci($n);

?>

OUTPUT :

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

QUE .14-WAP to check the year value whether it is leap year or not,
input enter by the user.
<html>

<body>

Mehak(02016702018)<br><br>

<form action="" method="post">

Enter the year<br>

<input type="text" name="year" /><br><br>

<input type="submit" /><br>

</form>

</body>

</html>

<?php

if( $_POST )

{ $year = $_POST[ 'year' ];

//check if entered value is a number

if(!is_numeric($year))

{ echo "Strings not allowed, Input should be a number";

return; }

if( (0 == $year % 4) and (0 != $year % 100) or (0 == $year % 400) )

{ echo "$year is a leap year"; }

else

{ echo "$year is not a leap year"; }

?>

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

OUTPUT :

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

QUE .15- WAP to take inputs of 5 student’s records related to 5


subjects marks & calculate their Total Marks, Percentage, Grade
Value (using switch cases & arrays).
<html>

<body>

Mehak(02016702018)<br><br>

<form>

<h4>Student_1 info</h4>

Name : <input type="text" name="name_1" placeholder = "Please Enter your name"><br>

ENGLISH : <input type="number" name="number1" placeholder = "Please enter your number"/><br>

MATHS : <input type="number" name="number2" placeholder = "Please enter your number"/><br>

HINDI : <input type="number" name="number3" placeholder = "Please enter your number"/><br>

OS : <input type="number" name="number4" placeholder = "Please enter your number"/><br>

PHYSICS : <input type="number" name="number5" placeholder = "Please enter your number"/><br>

<h4>Student_2 info</h4>

Name : <input type="text" name="name_2" placeholder = "Please Enter your name"><br>

ENGLISH : <input type="number" name="number6" placeholder = "Please enter your number"/><br>

MATHS : <input type="number" name="number7" placeholder = "Please enter your number"/><br>

HINDI : <input type="number" name="number8" placeholder = "Please enter your number"/><br>

OS : <input type="number" name="number9" placeholder = "Please enter your number"/><br>

PHYSICS : <input type="number" name="number10" placeholder = "Please enter your number"/><br>

<h4>Student_3 info</h4>

Name :<input type="text" name="name_3" placeholder = "Please Enter your name"><br>

ENGLISH : <input type="number" name="number11" placeholder = "Please enter your number"/><br>

MATHS : <input type="number" name="number12" placeholder = "Please enter your number"/><br>

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

HINDI : <input type="number" name="number13" placeholder = "Please enter your number"/><br>

OS : <input type="number" name="number14" placeholder = "Please enter your number"/><br>

PHYSICS : <input type="number" name="number15" placeholder = "Please enter your number"/><br>

<h4>Student_4 info</h4>

Name :<input type="text" name="name_4" placeholder = "Please Enter your name"><br>

ENGLISH : <input type="number" name="number16" placeholder = "Please enter your number"/><br>

MATHS : <input type="number" name="number17" placeholder = "Please enter your number"/><br>

HINDI : <input type="number" name="number18" placeholder = "Please enter your number"/><br>

OS : <input type="number" name="number19" placeholder = "Please enter your number"/><br>

PHYSICS : <input type="number" name="number20" placeholder = "Please enter your number"/><br>

<h4>Student_5 info</h4>

Name :<input type="text" name="name_5" placeholder = "Please Enter your name"><br>

ENGLISH : <input type="number" name="number21" placeholder = "Please enter your number"/><br>

MATHS : <input type="number" name="number22" placeholder = "Please enter your number"/><br>

HINDI : <input type="number" name="number23" placeholder = "Please enter your number"/><br>

OS : <input type="number" name="number24" placeholder = "Please enter your number"/><br>

PHYSICS : <input type="number" name="number25" placeholder = "Please enter your number"/><br>

<input type="submit" name="submit" value="calculate marks of 5 student" placeholder = "Please enter the
button">

</form>

</body>

</html>

<?php

@$name_1 = $_GET['name_1']; @$number1=$_GET['number1'];@$number2=$_GET['number2'];

@$number3=$_GET['number3']; @$number4=$_GET['number4'];@$number5=$_GET['number5'];

@$name_2 = $_GET['name_2']; @$number6=$_GET['number6']; @$number7=$_GET['number7'];

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

@$number8=$_GET['number8']; @$number9=$_GET['number9'];@$number10=$_GET['number10'];

@$name_3 = $_GET['name_3']; @$number11=$_GET['number11']; @$number12=$_GET['number12'];

@$number13=$_GET['number13']; @$number14=$_GET['number14']; @$number15=$_GET['number15'];

@$name_4 = $_GET['name_4']; @$number16=$_GET['number16']; @$number17=$_GET['number17'];

@$number18=$_GET['number18']; @$number19=$_GET['number19']; @$number20=$_GET['number20'];


@$name_5 = $_GET['name_5']; @$number21=$_GET['number21']; @$number22=$_GET['number22'];

@$number23=$_GET['number23'];@$number24=$_GET['number24'];@$number25=$_GET['number25'];

$student = array(

"Student_1" => array(

"name" => "$name_1",

"Total Marks" => $number1 + $number2 + $number3 + $number4 + $number5,

"Percentage" => (($number1 + $number2 + $number3 + $number4 + $number5) * 100)/500 . "%",

),

"Student_2" => array(

"name" => "$name_2",

"Total Marks" => $number6 + $number7 + $number8 + $number9 + $number10,

"Percentage" => (($number6 + $number7 + $number8 + $number9 + $number10) * 100)/500 . "%",

),

"Student_3" => array(

"name" => $name_3,

"Total Marks" => $number11 + $number12 + $number13 + $number14 + $number15,

"Percentage" => (($number11 + $number12 + $number13 + $number14 + $number15) * 100)/500 . "%",

),

"Student_4" => array(

"name" => $name_4,

"Total Marks" => $number16 + $number17 + $number18 + $number19 + $number20,

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

"Percentage" => (($number16 + $number17 + $number18 + $number19 + $number20) * 100)/500 . "%",

),

"Student_5" => array(

"name" => $name_5,

"Total Marks" => $number21 + $number22 + $number23 + $number24 + $number25,

"Percentage" => (($number21 + $number22 + $number23 + $number24 + $number25) * 100)/500 . "%"));

$percentage = array_column($student , "Percentage");

//print_r($percentage);

$keys = array_keys($student);

for($i = 0; $i < count($student); $i++) {

echo "<br>" . $keys[$i] . "{<br>";

foreach($student[$keys[$i]] as $key => $value) {

echo "<b>" . $key . " : " . $value . "</b><br>";

if(strpos($value, "%"))

calcGrade($value);

echo "<br>}<br><br>";

//echo "Percentage : " . $percentage[$i] . "<br>";

function calcGrade($num) {

$percentage = (int) str_replace("%", "", $num);

if ($percentage <= 100 && $percentage > 90) {

echo "Grade is : A+";

else if ($percentage <= 90 && $percentage > 80) {

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

echo "Grade is : A"; }

else if ($percentage <= 80 && $percentage > 70) {

echo "Grade is : B+";

else if ($percentage <= 70 && $percentage > 60) {

echo "Grade is : B";

else if ($percentage <= 60 && $percentage > 50) {

echo "Grade is : C+";

else if ($percentage <= 50 && $percentage > 40) {

echo "Grade is : C";

else

echo "Grade is : F";

?>

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)
OUTPUT :

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

QUE .16- WAP to calculate the factorial of a number using recursive


function, input entered by the user.
<html>

<body>

Mehak(02016702018) <br><br>

<form action="" method="post">

Enter number<br><br>

<input type="text" name="number" /><br><br>

<input type="submit" />

</form>

</body>

</html>

<?php

if($_POST){

$number= $_POST['number'];

function factorial($number) {

if ($number < 2) {

return 1;

} else {

return ($number * factorial($number-1));

} }

echo"Factorial of $number is :";

echo factorial($number);

}?>

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

OUTPUT :

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

QUE .17- WAP to calculate the sum of digits using function, input
entered by the user.
<html>

<body>

Mehak(02016702018)<br><br>

<form action="" method="get">

Enter the number whose digits you want to be added<br><br>

<input type="text" name="numb" /><br><br>

<input type="submit" /><br><br>

</form>

</body>

</html>

<?php

if($_GET){

function sum($num) {

$sum = 0;

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

$sum += $num[$i];

return $sum;

// Driver Code

$num = $_GET['numb'];

echo" The sum of digit $num is : ";

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

echo sum($num);

}?>

OUTPUT :

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

QUE .18-WAP to print the following pattern:-


*
**
***
****
*****
Input range entered by the user.
<html>

<head>

<title>patterns</title>

</head>

<body>

Mehak(02016702018)<br><br>

<form action="" method="get">

enter range<br>

<input type="text" name="ran" required > <br>

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

</form>

</body>

</html>

<?php

if(isset($_GET['sub'])){

$a=$_GET['ran'];

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

for($i=1;$i<=$a;$i++)

for($j=1;$j<=$i;$j++)

echo "* ";

echo "<br>";

}?>

OUTPUT :

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

QUE .19- WAP to print the following pattern:-


*
**
***
****
*****
Input range entered by the user.
<html>

<head>

<title>patterns</title>

</head>

<body>

Mehak(02016702018)<br><br>

<form action="" method="get">

enter range<br>

<input type="text" name="ran" required > <br>

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

</form>

</body>

</html>

<?php

if(isset($_GET['sub'])){

$a=$_GET['ran'];

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

for($i=1; $i<=$a; $i++) {

for($j=4; $j>=$i; $j--) //loop to print spaces

echo '&nbsp;&nbsp;';

for($k=1; $k<=$i; $k++) //loop to print stars

echo '*';

echo '<br>';

}?>

OUTPUT :

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

QUE .20- WAP to print the following pattern:-


*
***
*****
*******
*********
Input range entered by the user.
<html>

<body>

Mehak(02016702018)<br><br>

<form>

Enter a number :

<input type="number" name="number1" /><br><br>

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

</form>

<?php

@$number1=$_GET['number1'];

echo "Number enter by user : " . $number1 . "<br>";

for ($i=1; $i <=$number1 ; $i+=2)

for ($j=$number1; $j>$i ; $j--)

echo "&nbsp;";

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

for ($k=1; $k <=$i ; $k++)

echo "*";

echo "<br>";

?>

OUTPUT :

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

QUE .21- WAP to print the following pattern:-


*********
*******
*****
***
*
Input range entered by the user.
<html>

<body>

Mehak(02016702018)<br><br>

<form>

Enter a number :

<input type="number" name="number1" /><br><br>

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

</form>

<?php

@$number1=$_GET['number1'];

echo "Number enter by user : " . $number1 . "<br>";

if ($number1%2==0)

$number1 = $number1-1;

for ($i= $number1; $i >= 1 ; $i-=2)

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

for ($j=$number1 - 1; $j > $i ; $j--)

echo "&nbsp;";

for ($k=1; $k <= $i ; $k++)

echo " * ";

echo "<br>";

?>

OUTPUT :

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

QUE .22- WAP to print the following pattern:-


*
***
*****
*******
*****
***
*
Input range entered by the user.
<html>

<head>

<title>patterns</title>

</head>

<body>

Mehak(02016702018)<br><br>

<form action="" method="get">

enter range<br>

<input type="text" name="ran" required > <br>

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

</form>

</body>

</html>

<html><body><center>

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

<?php

if(isset($_GET['sub'])){

$a=$_GET['ran'];

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

{ for($k=$a;$k>=$i;$k--)

{ echo " "; }

for($j=1;$j<=$i;$j++)

{ echo "* "; }

echo "<br>";

for($i=$a-1;$i>=1;$i--)

for($k=$a;$k>=$i;$k--)

{ echo " "; }

for($j=1;$j<=$i;$j++)

{ echo "* "; }

echo "<br>";

?>

</center>

</body>

</html>

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

OUTPUT :

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

QUE .23- WAP to print the following pattern:-


1
121
12321
1234321
123454321
12345654321
1234567654321
Input range entered by the user.
<html>

<head>

<title>patterns</title>

</head>

<body>

Mehak(02016702018)<br><br>

<form action="" method="get">

enter range<br>

<input type="text" name="ran" required > <br>

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

</form>

</body>

</html>

<center>

<?php

if(isset($_GET['sub']))

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

$a=$_GET['ran'];

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

{ for($j=1; $j<=$a-$i; $j++)

{ echo" "; }

for($j=1; $j<=$i; $j++)

{ echo"$j"; }

for($j=$i-1; $j>=1; $j--)

{ echo"$j"; }

echo"<br>";

} }

?></center>

OUTPUT :

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

QUE .24- WAP to build a connection with MySQL server and create a
database name as mydb.
<html>

<body>

Mehak(02016702018)<br><br><br>

</body>

</html>

<?php

$servernsme = "localhost";

$username = "root";

$password = "";

$conn = mysqli_connect($servernsme, $username, $password) or die($conn);

$create_db = "CREATE DATABASE mydb";

if(mysqli_query($conn, $create_db) )

echo"database created successfully";

else

echo"database creation unsuccessfull <br>";

echo" There might be an existing database with the same name.";

mysqli_close($conn);

?>

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

OUTPUT :

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

QUE .25- WAP to create a employee table in mydb database which


have fields like Emp_Id, Emp_Name, Emp_Salary, Emp_DOB.
<html>

<body>

Mehak(02016702018)<br><br><br>

</body>

</html>

<?php

// Create connection

$conn = mysqli_connect('localhost', 'root', '', 'mydb');

// Check connection

if (!$conn) {

die("Connection failed: " . mysqli_connect_error());

// sql to create table

$create_table = "CREATE TABLE employee (

Emp_id INT(6) AUTO_INCREMENT PRIMARY KEY,

Emp_name VARCHAR(30) NOT NULL,

Emp_DOB date NOT NULL,

Emp_salary int(8) NOT NULL

)";

if (mysqli_query($conn, $create_table))

echo "Table 'employee' created successfully";

else

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

echo "Error creating table: " . mysqli_error($conn);

mysqli_close($conn);

?>

OUTPUT :

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

QUE .26- WAP to insert atleast 10 records in employee table, which is


inside mydb database.
<html>

<head>

<title>

Entering data into employe table

</title>

</head>

<body>

Mehak(02016702018)<br><br>

<center>

<h3> Enter data in employee table </h3>

<form action="" method="post">

<input type="text" placeholder=" Employee name" name="name" required> <br>

<input type="date" placeholder=" Date of birth" name="dob" required> <br>

<input type="text" placeholder=" Salary (in rupees)" name="sal" required> <br>

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

</center>

</form>

</body>

</html>

<?php

$conn = mysqli_connect('localhost', 'root', '', 'mydb');

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

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

$name = $_POST['name'];

$dob = $_POST['dob'];

$salary = $_POST['sal'];

$sql = "INSERT INTO employee (Emp_name, Emp_DOB, Emp_salary)

VALUES ('$name','$dob','$salary')";

if (mysqli_query($conn, $sql)) {

echo "New record has been added successfully for $name!";

} else {

echo "Error: " . $sql . ":-" . mysqli_error($conn);

mysqli_close($conn); }

?>

OUTPUT :

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

QUE .27-WAP to update any one record in the employee table, which
is in mydb database.
<html>

<head>

<title>

Entering data into employe table

</title>

</head>

<body>

Mehak(02016702018)<br><br>

<center>

<h3>Update an employee data </h3>

<hr>

<h6>Enter current id and updated data in other fields</h6>

<form action="" method="post">

<input type="text" placeholder=" ID" name="id" required> <br>

<input type="text" placeholder=" Employee name" name="name" required> <br>

<input type="text" placeholder=" Date of birth" name="dob" required> <br>

<input type="text" placeholder=" Salary (in rupees)" name="sal" required> <br>

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

<h4> NOTE:- ID cant be updated </h4>

</center>

</form>

</body>

</html>

<?php

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

$conn = mysqli_connect('localhost', 'root', '', 'mydb');

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

$name = $_POST['name'];

$dob = $_POST['dob'];

$salary = $_POST['sal'];

$ID = $_POST['id'];

$update = "UPDATE employee SET Emp_name='$name', EMP_DOB='$dob',


EMP_salary='$salary' WHERE Emp_id='$ID'";

if (mysqli_query($conn, $update)) {

echo "New record has been added successfully for $name!";

} else {

echo "Error: " . $sql . ":-" . mysqli_error($conn);

mysqli_close($conn);

?>

OUTPUT :

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

QUE .28-WAP to design a format & display all records from the
employee table, which is in mydb database.
<?php

$conn = mysqli_connect('localhost', 'root', '', 'mydb');

$select= "select Emp_id , Emp_name, Emp_DOB, Emp_salary from employee";

$select_result= mysqli_query($conn, $select);

$row= mysqli_fetch_array($select_result);

?>

<!doctype html>

<html lang="en">

<head>

<meta charset="utf-8">

<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css"


integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2"
crossorigin="anonymous">

<title>Employees</title>

</head>

<body>

<center>Mehak(02016702018)<br><br></center>

<div class="container">

<div class="row">

<div class="col-lg-12"><h4>Employees</h4></div>

</div>

<div class="container">

<?php while($row= mysqli_fetch_array($select_result)) { ?>

<div class="row">

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

<div class="col-lg-2">ID</div>

<div class="col-lg-10"><?php echo $row['Emp_id']; ?></div>

</div>

<div class="row">

<div class="col-lg-2">Name</div>

<div class="col-lg-10"><?php echo $row['Emp_name']; ?></div>

</div>

<div class="row">

<div class="col-lg-2">DOB</div>

<div class="col-lg-10"><?php echo $row['Emp_DOB']; ?></div>

</div>

<div class="row">

<div class="col-lg-2">Salary</div>

<div class="col-lg-10"><?php echo $row['Emp_salary']; ?></div>

</div>

<hr/>

<?php } ?>

</div>

</body>

</html>

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)
OUTPUT :

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

QUE .29- WAP to delete a particular record form the employee table,
which is in mydb database.
<html>

<head>

<title>

deleting a particular data from the table

</title>

</head>

<body><center>

Mehak(02016702018)<br><br>

<h3>Deleting an employee </h3>

<hr>

<h5>Enter the ID of an employee who is to be deleted</h5>

<form action="" method="post">

<input type="text" name="id" placeholder="" required> <br>

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

</center>

</form>

</body>

</html>

<?php

$conn = mysqli_connect('localhost', 'root', '', 'mydb');

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

$ID = $_POST['id'];

$delete= "DELETE from employee where Emp_id='$ID'";

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

if (mysqli_query($conn, $delete)) {

echo "Record has been deleted successfully !";

} else {

echo "Error: " . $sql . ":-" . mysqli_error($conn);

mysqli_close($conn);

?>

OUTPUT :

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

QUE .30- WAP to design a format & display all records from the
employee table, which is in mydb database (Using select query with
order by clause).
<h4> <center>Mehak(02016702018)<BR><BR></center>

<h3 align='center'> Data of employee table arranged by ascending order of the salaries</h3>

<hr>

<?php

$link =mysqli_connect('localhost', 'root', '', 'mydb');

$sql = "SELECT * FROM employee ORDER BY Emp_salary";

if($res = mysqli_query($link, $sql)){

if(mysqli_num_rows($res) > 0){

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

echo "<tr>";

echo "<th>id</th>";

echo "<th>name</th>";

echo "<th>dob</th>";

echo "<th>salary</th>";

echo "</tr>";

while($row = mysqli_fetch_array($res)){

echo "<tr>";

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

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

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

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

echo "</tr>";

MEHAK
(02016702018)
PHP Practical File BCA V Sem(morning)

echo "</table></centre>";

mysqli_free_result($res);

} else{

echo "No matching records are found.";

} else{

echo "ERROR: Could not able to execute $sql. "

. mysqli_error($link); }

mysqli_close($link);

?>

OUTPUT :

MEHAK
(02016702018)

You might also like