You are on page 1of 89

MCA 206 Software Development Lab-II(php)

DePaul Institute of Science & Technology(DIST) Page NO.


OUTPUT
MCA 206 Software Development Lab-II(php)

PROGRAM NO: 1 DATE: 13-09-2021

AIM: Program to find the grade of a student by entering subject marks.

PROGRAM:

<html>
<body>
<form method="POST">
<center><h1><u>Grade of a Student</u></h1>
<table>
<tr><td>Enter the name of student:</td>
<td><input type="text" name="name"></td></tr>
<tr><td>Enter class:</td><td><input type="text" name="class"></td></tr>
<tr><td>***Enter marks in 3 subjects </td><td>(out of 100)***</td></tr>
<tr><td>Enter the mark of first subject:</td>
<td><input type="text" name="sub1"></td></tr>
<tr><td>Enter the mark of second subject:</td>
<td><input type="text" name="sub2"></td></tr>
<tr><td>Enter the mark of third subject:</td>
<td><input type="text" name="sub3"></td></tr>
<tr><td></td><td><input type="submit" name="submit"></center>
</td></tr></table></center>
</form><br><br>
<?php
if(isset($_POST['submit']))
{
$n1=$_POST["name"];
$n2=$_POST["class"];
$s1=$_POST["sub1"];
$s2=$_POST["sub2"];
$s3=$_POST["sub3"];
$total=$s1+$s2+$s3;
$per=$total/3;
echo "<center>------DETAILS--------<br><br>

DePaul Institute of Science & Technology(DIST) Page NO.


MCA 206 Software Development Lab-II(php)

name of student : $n1 <br>


class : $n2<br><br>total mark obtained=$total <br>
percentage=$per</center>";
if($per<=100 && $per>=90)
{
echo"<center>S grade</center>";
}
elseif ($per<=89&&$per>=80)
{
echo "<center>A grade</center>";
}
elseif($per<=79&&$per>=70)
{
echo"<center>B grade</center>";
}
elseif($per<=69&&$per>=60)
{
echo"<center>C grade</center>";
}
elseif ($per<=59&&$per>=50)
{
echo "<center>D grade</center>";
}
else
{
echo "<center>Fail</center>";
}
}
?>
</body>
</html>

DePaul Institute of Science & Technology(DIST) Page NO.


OUTPUT
MCA 206 Software Development Lab-II(php)

PROGRAM NO: 2 DATE: 13-09-2021

AIM: Program to swap two numbers.

PROGRAM:

<html>
<body>
<center><h1><u>Swap 2 nos</u></h1>
<form method="post">
<table>
<tr><td>Enter first number:</td>
<td><input type="number" name="num1"></td></tr>
<tr><td>Enter second number:</td>
<td><input type="number" name="num2"></td></tr>
<tr><td></td><td><input type="submit" name="submit" value="swap"></td></tr>
</table>
</form>
<?php
if ($_POST)
{
$a=$_POST['num1'];
$b=$_POST['num2'];
echo "<center>Before swapping: first number=$a,second number=$b</center>";
$t=$a;
$a=$b;
$b=$t;
echo "<br><center>After swapping: first number=$a,second number=$b</center>";
}
?>
</center>
</body>
</html>

DePaul Institute of Science & Technology(DIST) Page NO.


OUTPUT
MCA 206 Software Development Lab-II(php)

PROGRAM NO: 3 DATE: 13-09-2021

AIM: Program to rotate three values of variables.

PROGRAM:

<html>
<body>
<center><h1><u>Rotate 3 nos</u></h1>
<form method="post">
<table>
<tr><td>Enter first number:</td><td> <input type="number" name="num1"></td></tr>
<tr><td>Enter second number:</td><td> <input type="number"
name="num2"></td></tr>
<tr><td>Enter third number:</td><td><input type="number" name="num3"></td></tr>
<tr><td></td><td><input type="submit" name="submit" value="Rotate"></td></tr>
</table></form>
<?php
if ($_POST)
{
$a=$_POST['num1'];
$b=$_POST['num2'];
$c=$_POST['num3'];
echo "<center>Before rotation: $a,$b,$c</center>";
$t=$a;
$a=$b;
$b=$c;
$c=$t;
echo "<br><center>After rotation: $a,$b,$c</center>";
}
?>
</center>
</body>
</html>

DePaul Institute of Science & Technology(DIST) Page NO.


OUTPUT
MCA 206 Software Development Lab-II(php)

PROGRAM NO: 4 DATE: 13-09-2021

AIM: Program to find length of a string.

PROGRAM:

<html>
<body>
<center><h1><u>Length of a String</u></h1>
<form method="POST" >
<table><tr><td>Enter your string:</td>
<td><input type="text" name="str"></td></tr>
<tr><td></td><td><input type="submit" name="submit"></td></tr>
</table><br><br>
<?php
if(isset($_POST['submit']))
{
$st=$_POST["str"];
$l=strlen($st);
echo "<center>String=$st <br> Length of the string is $l</center>";
}
?>
</center>
</body>
</html>

DePaul Institute of Science & Technology(DIST) Page NO.


OUTPUT
MCA 206 Software Development Lab-II(php)

PROGRAM NO: 5 DATE: 13-09-2021

AIM: Program to find area of a Triangle,Rectangle and a Cube.

PROGRAM:

<html>
<body><center><h1><u>Area of Shapes</u></h1>
<form method="post"><table>
<tr><td>Enter the base for triangle:</td><td>
<input type="number" name="base"></td></tr>
<tr><td>Enter the height for triangle:</td>
<td><input type="number" name="height"></td></tr>
<tr><td>Enter the breadth for rectangle:</td>
<td><input type="number" name="breadth"></td></tr>
<tr><td>Enter the length for rectangle:</td>
<td><input type="number" name="length"></td></tr>
<tr><td>Enter the side of cube:</td>
<td><input type="number" name="side"></td></tr>
<tr><td></td><td><input type="submit" name="submit"></td>
</tr></table>
</form>
<?php
if(isset($_POST['submit']))
{
$b=$_POST["base"];
$h=$_POST["height"];
$w=$_POST["breadth"];
$l=$_POST["length"];
$a=$_POST["side"];
echo "<center><u>RESULTS</u><br><br></center>";
$t=($b*$h)/2;
$r=$w*$l;
$c=6*$a*$a;
echo "<center>---Area of Triangle---</center>";

DePaul Institute of Science & Technology(DIST) Page NO.


MCA 206 Software Development Lab-II(php)

echo "area of triangle : $t<br>";


echo "<center><br>---Area of Rectangle---</center>";
echo "area of rectangle : $r<br>";
echo "<center><br>---Area of Cube---</center>";
echo "area of cube : $c";
}
?>
<center>
</body>
</html>

DePaul Institute of Science & Technology(DIST) Page NO.


OUTPUT
MCA 206 Software Development Lab-II(php)

PROGRAM NO: 6 DATE: 13-09-2021

AIM: Program to print n natural numbers.

PROGRAM:

<html>
<body><center><h1><u>N natural nos</u></h1>
<form method="POST">
<table>
<tr><td><input type="text" name="input" placeholder="enter limit"></td></tr>
<tr><td><input type="submit" name="submit"></td></tr>
</table>
</form>
<?php
if(isset($_POST['submit']))
{
$a=$_POST['input'];
echo "<center> First $a natural nos are:</center>";
for($i=1;$i<=$a;$i++)
{
echo"$i";
echo"<br>";
}
}
?>
</center>
</body>
</html>

DePaul Institute of Science & Technology(DIST) Page NO.


OUTPUT
MCA 206 Software Development Lab-II(php)

PROGRAM NO: 7 DATE: 13-09-2021

AIM: Program to find sum of digits of a number.

PROGRAM:

<html>
<body><center><h1><u>Sum of digits of a no.</u></h1>
<form method="post">
<table>
<tr>
<td> <input type="text" name="num" value="" placeholder="Enter a number"/> </td>
</tr>
<tr>
<td> <input type="submit" name="submit" value="Submit"/> </td>
</tr>
</table>
</form>
<?php
if(isset($_POST['submit']))
{
$n=$_POST["num"];
echo "<center>no. is : $n</center>";
$sum=0;
while($n!=0)
{
$rem=$n%10;
$sum=$sum+$rem;
$n=$n/10;
}
echo "<center><br>sum of digits : $sum</center>";
}
?></center>
</body>
</html>

DePaul Institute of Science & Technology(DIST) Page NO.


OUTPUT
MCA 206 Software Development Lab-II(php)

PROGRAM NO: 8 DATE: 14-09-2021

AIM: Program to print even & odd numbers in between a range of values.

PROGRAM:

<html>
<body><center><h1><u>Even and Odd Nos between Ranges</u></h1>
<form method="post">
<label>Enter range 1:</label>
<input type="number" name="range1"><br><br>
<label>Enter range 2:</label>
<input type="number" name="range2"><br><br>
<input type="submit" name="submit" value="submit">
</form>
<?php
if(isset($_POST['submit']))
{
$num1 = $_POST['range1'];
$num2 = $_POST['range2'];
$even= "<br>Even Numbers between $num1 and $num2 Are : ";
$odd="<br><br> Odd Numbers between $num1 and $num2 Are : ";
for($i=$num1; $i<=$num2; $i++)
{
if($i%2==0)
{
$even.=$i.",";
}
else
$odd.=$i.",";
}
echo $even.$odd;
}
?></center>
</body></html>

DePaul Institute of Science & Technology(DIST) Page NO.


OUTPUT
MCA 206 Software Development Lab-II(php)

PROGRAM NO: 9 DATE: 14-09-2021

AIM: Program to print day of the week.

PROGRAM:

<html>
<body><center><h1><u>Day of Week</u></h1>
<form method="post">
<label>Enter week number(1-7):</label>
<input type="number" name="n1"><br><br>
<input type="submit" name="submit" value="submit">
</form>
<?php
function day()
{
if(isset($_POST['submit'])){
$d=$_POST["n1"];
switch ($d)
{
case '1':
echo "It is Monday";
break;
case '2':
echo "It is Tuesday";
break;
case '3':
echo "It is Wednesday";
break;
case '4':
echo "It is Thursday";
break;
case '5':
echo "It is Friday";
break;

DePaul Institute of Science & Technology(DIST) Page NO.


MCA 206 Software Development Lab-II(php)

case '6':
echo "It is Saturday";
break;
case '7':
echo "It is Sunday";
break;
default:
echo "Invalid input";
break;
}
}
}
day();
?>
</center>
</body>
</html>

DePaul Institute of Science & Technology(DIST) Page NO.


OUTPUT
MCA 206 Software Development Lab-II(php)

PROGRAM NO: 10 DATE: 14-09-2021

AIM: Program to check whether a number is palindrome or not.

PROGRAM:

<html>
<body><center><h1><u>Palindrome or Not</u></h1>
<form method="post"><label>Enter a number:</label>
<input type="number" name="n1"><br><br>
<input type="submit" name="submit" value="submit"></form>
<?php
function Palindrome() {
if(isset($_POST['submit'])) {
$num1=$_POST["n1"];
{
$t=$num1;
$s=0;
while(floor($num1)) {
$r=$num1%10;
$s=$s*10+$r;
$num1=$num1/10;
}
if($t==$s) {
echo "$t is a palindrome no.!";
}
else {
echo "$t is not a palindrome no.!";
}}
}}
Palindrome();
?>
</center>
</body>
</html>

DePaul Institute of Science & Technology(DIST) Page NO.


OUTPUT
MCA 206 Software Development Lab-II(php)

PROGRAM NO: 11 DATE: 14-09-2021

AIM: Program to check whether a number is armstrong or not.

PROGRAM:

<html>
<body><center><h1><u>Armstrong or Not</u></h1>
<form method="post"> <label>Enter a number:</label>
<input type="number" name="n1"><br><br>
<input type="submit" name="submit" value="submit">
</form>
<?php
function arm() {
if(isset($_POST['submit'])) {
$num1=$_POST["n1"];
{
$t=$num1;
$s=0;
while(floor($num1)) {
$r=$num1%10;
$s=$s+($r*$r*$r);
$num1=$num1/10;
}
if($t==$s) {
echo "$t is an armstrong no.!";
}
else {
echo "$t is not an armstrong no.!";
}}
}}
arm();
?>
</center>
</body></html>

DePaul Institute of Science & Technology(DIST) Page NO.


OUTPUT
MCA 206 Software Development Lab-II(php)

PROGRAM NO: 12 DATE: 14-09-2021

AIM: Program to find the length of a string using user-defined function.

PROGRAM:
<html>
<body><center><h1><u>Length of String using user-defined function</u></h1>
<form method="post">
<label>Enter a string:</label>
<input type="text" name="s1"><br><br>
<input type="submit" name="submit" value="submit">
</form></center>
<?php
function st()
{
if(isset($_POST['submit']))
{
$s=$_POST["s1"];
echo "<br><br><center>Entered string : $s</center><br>";
$l=strlen($s);
echo "<center>Its length : $l</center>";
}
}
st();
?>
</body>
</html>

DePaul Institute of Science & Technology(DIST) Page NO.


OUTPUT
MCA 206 Software Development Lab-II(php)

PROGRAM NO: 13 DATE: 14-09-2021

AIM: Program to generate prime numbers upto a limit.

PROGRAM:
<html>
<body><center><h1><u>Prime nos upto a limit</u></h1>
<form method="post"><label>Enter limit:</label>
<input type="number" name="range1"><br><br>
<input type="submit" name="submit" value="submit">
</form></center>
<?php
if(isset($_POST['submit']))
{
$num1 = $_POST['range1'];
$prime="<br><center>prime nos upto $num1 are:</center>";
for($i=1;$i<=$num1;$i++)
{
$c=0;
for($j=1;$j<=$num1;$j++)
{
if($i%$j==0)
{
$c=$c+1;
}
}
if($c==2)
{
$prime.=$i.",";
}
}echo "<center>$prime</center>";
}
?>
</body></html>

DePaul Institute of Science & Technology(DIST) Page NO.


OUTPUT
MCA 206 Software Development Lab-II(php)

PROGRAM NO: 14 DATE: 14-09-2021

AIM: Program to print factorial of a number.

PROGRAM:
<html>
<body><center><h1><u>Factorial</u></h1>
<form method="post">
<label>Enter no:</label>
<input type="number" name="n1"><br><br>
<input type="submit" name="submit" value="submit">
</form></center>
<?php
if(isset($_POST['submit']))
{
$num1 = $_POST['n1'];
$factorial="<br><center>Factorial of $num1 is:</center>";
$f=1;
while($num1>0)
{
$f=$f*$num1;
$num1--;
}
$factorial.=$f;
echo "<center>$factorial</center>";
}
?>
</body>
</html>

DePaul Institute of Science & Technology(DIST) Page NO.


OUTPUT
MCA 206 Software Development Lab-II(php)

PROGRAM NO: 15 DATE: 14-09-2021

AIM: Program to generate Fibonacci series

PROGRAM:

<html>
<body><center><h1><u>Fibonacci series</u></h1>
<form method="post">
<label>Enter limit:</label>
<input type="number" name="n1"><br><br>
<input type="submit" name="submit" value="submit">
</form></center>
<?php
if(isset($_POST['submit']))
{
$num1 = $_POST['n1'];
$x=0;$y=1;$z=0;
echo "<br><center>Fibonacci series upto $num1 are:</center>";
echo "<br><center>$x</center><br>";
echo "<br><center>$y</center><br>";
for($i=0;$i<$num1-2;$i++)
{
$z=$x+$y;
echo "<br><center>$z</center><br>";
$x=$y;
$y=$z;
}
}
?>
</body>
</html>

DePaul Institute of Science & Technology(DIST) Page NO.


OUTPUT
MCA 206 Software Development Lab-II(php)

PROGRAM NO: 16 DATE: 04-10-2021

AIM: Program to print Integer Arrays.

PROGRAM:

<html>
<body><center>
<h1><u>Integer Arrays</u></h1>
<?php
$arr=array(10,20,30,40,50);
echo "array=[$arr[0],$arr[1],$arr[2],$arr[3],$arr[4]]<br>";
echo "array elements are:<br>";
for($i=0;$i<5;$i++)
{
echo "$arr[$i]<br>";
}
?></center>
</body>
</html>

DePaul Institute of Science & Technology(DIST) Page NO.


OUTPUT
MCA 206 Software Development Lab-II(php)

PROGRAM NO: 17 DATE: 04-10-2021

AIM: Program to read elements into an array and print it.

PROGRAM:

<html>
<body><center><h1><u>Array</u></h1>
<?php
print "<b>Enter elements:</b>";
print "<form method=post>";
for($i=0;$i<4;$i++)
{
print "<input type=text name=txt$i size=5>";
}
print "<br><br><input type=submit name=submit value=submit>";
print "</form>";
$arr=array();
if(isset($_POST['txt0']))
{
for($i=0;$i<4;$i++)
{
$arr[$i]=$_POST['txt'.$i];
}
print_r($arr);
echo "<br>array elements are:";
for($i=0;$i<4;$i++)
{
print "<br>$arr[$i]";
}
}
?>
</center>
</body>
</html>

DePaul Institute of Science & Technology(DIST) Page NO.


OUTPUT
MCA 206 Software Development Lab-II(php)

PROGRAM NO: 18 DATE: 04-10-2021

AIM: Program to print name & age of 5 persons using array.

PROGRAM:

<html>
<body><center>
<h1><u>Name and Age of 5 persons</u></h1>
<?php
$age=array("Treesa"=>"22","Ninu"=>"22","Rudy"=>"3","Tinku"=>"4");
echo "Treesa is&nbsp;" . $age['Treesa'] . "&nbsp;years old<br>";
echo "Ninu is&nbsp;" . $age['Ninu'] . "&nbsp;years old<br>";
echo "Rudy is&nbsp;" . $age['Rudy'] . "&nbsp;years old<br>";
echo "Tinku is&nbsp;" . $age['Tinku'] . "&nbsp;years old<br>";
?>
</center>
</body>
</html>

DePaul Institute of Science & Technology(DIST) Page NO.


OUTPUT
MCA 206 Software Development Lab-II(php)

PROGRAM NO: 19 DATE: 04-10-2021

AIM: To create class a student & print details using member functions .

PROGRAM:

<html>
<head></head>
<body><center><h1><u>Student Details using class & member functions</u></h1>
<?php
class student {
public $name;
public $roll;
public $class;
public $batch;
function set_name($n,$r,$c,$b) {
$this->name = $n;
$this->roll=$r;
$this->class = $c;
$this->batch=$b;
}
function get_name() {
echo"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NAME : $this->name";
echo "<br>ROLL NO. : $this->roll";
echo "<br>CLASS : &nbsp;&nbsp;$this->class";
echo "<br>BATCH : $this->batch";
}
}
$s1 = new student();
$s1->set_name('TREESA BOBAN',38,'MCA','20-22');
$s1->get_name();
?>
</center>
</body></html>

DePaul Institute of Science & Technology(DIST) Page NO.


OUTPUT
MCA 206 Software Development Lab-II(php)

PROGRAM NO: 20 DATE: 04-10-2021

AIM: Program to implement Inheritance.

PROGRAM:

<html>
<body><center><h1><u>Inheritance</u></h1>
<?php
class name {
public $name;
public $no;
public function __construct($name, $no) {
$this->name = $name;
$this->no = $no;
}
public function set1() {
echo "<br><br>Name:$this->name<br>Roll_no:$this->no";
}}
class Stud extends name {
public function set2() {
echo "<b>DETAILS</b><br>";
}}
class c extends Stud {
public function set3() {
echo "<b>MCA 2020</b><br>";
}}
$c = new c("Treesa", "38");
$c1 = new c("ninu", "20");
$c->set3();
$c->set2();
$c->set1();
$c1->set1();
?></center>
</body></html>

DePaul Institute of Science & Technology(DIST) Page NO.


OUTPUT
MCA 206 Software Development Lab-II(php)

PROGRAM NO: 21 DATE: 04-10-2021

AIM: Program to create a Login form and validate it.

PROGRAM:

<html>
<body>
<center><h1><u>Login form and validation</u></h1><br><br>
<h2>Login Here....</h2><br><br>
<form action="" method="post">
<table><tr><td><label>EMAIL</label>
</td><td>:<input type="text" name="email"></td></tr>
<tr></tr><tr><td><label>PASSWORD</label></td>
<td>:<input type="password" name="pswd"></td>
</tr><tr></tr><tr></tr><tr></tr><tr><td></td>
<td><input type="submit" value="Login"></td>
</tr></table></form>
<?php
if(empty($_POST["email"]))
{
$errMsg = "<br>Error! You didn't enter the Email.";
echo $errMsg;
}
else
{
$email = $_POST ["email"];
$pattern = "^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$^";
if (!preg_match ($pattern, $email) )
{
$ErrMsg = "<br>Email is not valid.";
echo $ErrMsg;
}
else
{

DePaul Institute of Science & Technology(DIST) Page NO.


MCA 206 Software Development Lab-II(php)

echo "<br>Your valid email address is: " .$email;


}
}
if(empty($_POST["pswd"]))
{
$errMsg = "<br>Error! You didn't enter the Password.";
echo $errMsg;
}
else
{
$psd = $_POST["pswd"];
if(strlen ($psd) < 6 )
{
$ErrMsg = "<br>Password must have 6 characters.";
echo $ErrMsg;
}
else
{
$pswd = $_POST["pswd"];
echo "<br>Done!!";
echo "<br>Login Successfull!!";
}
}
?>
</center>
</body>
</html>

DePaul Institute of Science & Technology(DIST) Page NO.


OUTPUT
MCA 206 Software Development Lab-II(php)

PROGRAM NO: 22 DATE: 04-10-2021

AIM: Program to create an Application form and validate it.

PROGRAM:
<html><body><center><h1><u>Application Form Validation</u></h1><br><br>
<h2>Fill up...</h2><form action="" method="post">
<table><tr><td><label>NAME</label></td>
<td>:<input type="text" name="name"></td></tr>
<tr><td><label>ADDRESS</label></td>
<td>:<input type="text" name="add"></textarea></td></tr>
<tr><td><label>AGE</label></td>
<td>:<input type="text" name="age"></td></tr>
<tr><td><label>PHONE</label></td>
<td>:<input type="text" name="phone"></td></tr>
<tr><td><label>DOB</label></td>
<td>:<input type="date" name="date"></td></tr>
<tr><td><label>EMAIL</label></td>
<td>:<input type="text" name="email"></td></tr>
<tr><td><label>PASSWORD</label></td>
<td>:<input type="password" name="pswd"></td></tr>
<tr><td></td><td><input type="submit" value="Submit"></td></tr></table></form>
<?php
echo "<b>---Details---</b><br>";
if(empty($_POST["name"])){
$errMsg = "<br>Error! You didn't enter the Name.";
echo $errMsg;
}
else {
$name = $_POST["name"];
if (!preg_match ("/^[a-zA-z]*$/", $name) ) {
$ErrMsg = "<br>Only alphabets and whitespace are allowed.";
echo $ErrMsg;
}

DePaul Institute of Science & Technology(DIST) Page NO.


MCA 206 Software Development Lab-II(php)

else {
echo "<br>Your Name is: " .$name;
}}
if(empty($_POST["add"])) {
$errMsg = "<br>Error! You didn't enter the Address.";
echo $errMsg;
}
else {
$add = $_POST["add"];
if (!preg_match ("/^[a-zA-z]*$/", $add) ) {
$ErrMsg = "<br>Only alphabets and whitespace are allowed.";
echo $ErrMsg;
}
else {
echo "<br>Your Address is: " .$add;
}}
if(empty($_POST["age"])) {
$errMsg = "<br>Error! You didn't enter the Age.";
echo $errMsg;
}
else {
$age = $_POST["age"];
echo "<br>Your Age is: " .$age;
}
if(empty($_POST["phone"])) {
$errMsg = "<br>Error! You didn't enter the Number.";
echo $errMsg;
}
else {
$phone = $_POST["phone"];
if(strlen ($phone) != 10 ) {
$ErrMsg = "<br>Mobile number must have 10 digits.";
echo $ErrMsg;
}

DePaul Institute of Science & Technology(DIST) Page NO.


MCA 206 Software Development Lab-II(php)

elseif(!preg_match ("/^[0-9]*$/", $phone) ) {


$ErrMsg = "<br>Only numeric values are allowed.";
echo $ErrMsg;
}
else {
echo "<br>Your Mobile number is: " .$phone;
}}
if(empty($_POST["date"])) {
$errMsg = "<br>Error! You didn't enter the DOB.";
echo $errMsg;
}
else {
$date = $_POST["date"];
echo "<br>Your DOB is: " .$date;
}
if(empty($_POST["email"])) {
$errMsg = "<br>Error! You didn't enter the Email.";
echo $errMsg;
}
else {
$email = $_POST ["email"];
$pattern = "^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$^";
if (!preg_match ($pattern, $email) ) {
$ErrMsg = "<br>Email is not valid.";
echo $ErrMsg;
}
else {
echo "<br>Your valid email address is: " .$email;
}}
if(empty($_POST["pswd"])) {
$errMsg = "<br>Error! You didn't enter the Password.";
echo $errMsg;
}
else {

DePaul Institute of Science & Technology(DIST) Page NO.


MCA 206 Software Development Lab-II(php)

$psd = $_POST["pswd"];
if(strlen ($psd) < 6 ) {
$ErrMsg = "<br>Password must have 6 characters.";
echo $ErrMsg;
}
else {
$pswd = $_POST["pswd"];
echo "<br>Done!!";
}}
?>
</center>
</body>
</html>

DePaul Institute of Science & Technology(DIST) Page NO.


OUTPUT
MCA 206 Software Development Lab-II(php)

PROGRAM NO: 23 DATE: 05-10-2021

AIM: Create a student database with atleast 4 fields and perform the operations such as
insertion,deletion,updation and selection by making php as front end.

PROGRAM:
**studentdatabase.php**
<html>
<body>
<?php
/*if($_POST)
{
$servername="localhost";
$username="";
$password="";
$databasename="studentdb";
$conn=new mysqli($servername,$username,$password,$databasename);
if($conn->connect_error)
{
echo"connection error";
}
else
echo"connection successfull";
$name=$_POST['name'];
$address=$_POST['address'];
$age=$_POST['age'];
$course=$_POST['course'];
$sql="insert into stud values($name,$address,$age,$course)";
if(mysqli_query($conn,$sql))
{
echo "inserted successfully";
}
else
echo "inserted unsuccessfully";

DePaul Institute of Science & Technology(DIST) Page NO.


MCA 206 Software Development Lab-II(php)

//mysqli_close($conn);
}*/
?>
<?php
$servername = "172.16.0.6";
$username = "mca20";
$password = "mca";
$databasename="mca20db";
// Create connection
$conn = new mysqli($servername, $username, $password,$databasename);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
$name=$_POST['name'];
$address=$_POST['address'];
$age=$_POST['age'];
$course=$_POST['course'];
$sql="insert into stud38(name,address,age,course)
values('$name','$address',$age,'$course')";
//$sql = "INSERT INTO stud (sid,sname,age) VALUES (6, 'indhu', 25)";
if (mysqli_query($conn, $sql)) {
echo "<br>New record created successfully";
} else {
echo "<br>Error: " . $sql . "<br>" . mysqli_error($conn);
}
mysqli_close($conn);
?><br><br>
<input type="button" value="Back to home" onclick="window.location.href =
'studentmain.html'" />
</body>
</html>
**studentdatabasehtml.html**

DePaul Institute of Science & Technology(DIST) Page NO.


MCA 206 Software Development Lab-II(php)

<html>
<body>
<center>
<h1>Insert Record</h1>
<img src="image.jpeg" width="800" height="400"><br>
<form action="studentdatabase.php" method=post>
<table>
<tr><td>NAME :</td><td><input type=text name="name"></td></tr>
<tr><td>ADDRESS :</td><td><input type=text name="address"></td></tr>
<tr><td>AGE :</td><td><input type=number name="age"></td></tr>
<tr><td>COURSE :</td><td><input type=text name="course"></td></tr>
<tr><td></td><td><input type=submit name="submit" value="submit"></td></tr>
</table>
</form>
</center>
</body>
</html>
**studentdelete.php**
<html>
<body><?php
$servername = "172.16.0.6";
$username = "mca20";
$password = "mca";
$databasename="mca20db";
// Create connection
$conn = new mysqli($servername, $username, $password,$databasename);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
$name=$_POST['name'];
$sql="delete from stud38 where name='$name'";
//$sql = "INSERT INTO stud (sid,sname,age) VALUES (6, 'indhu', 25)";
if (mysqli_query($conn, $sql)) {
echo "\ndeleted successfully";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
mysqli_close($conn);
?>
<br><br><input type="button" value="Back to home" onclick="window.location.href =
'studentmain.html'" />
</body>

DePaul Institute of Science & Technology(DIST) Page NO.


MCA 206 Software Development Lab-II(php)

</html>
**delete.html**
<html>
<body><center>
<h1>Delete Record</h1>
<img src="image.jpeg" width="800" height="400"><br>
<form action="studentdelete.php" method=post>
<table>
<tr><td>Name to delete :</td><td><input type=text name="name"></td></tr>
<tr><td></td><td><input type=submit name="submit" value="submit"></td></tr>
</table>
</form>
</center>
</body>
</html>
**studentmain.html**
<!DOCTYPE html>
<html>
<head>
</head>
<style>
/*body
{
background-image: url('image.jpeg');
background-repeat: no-repeat;
background-size: cover;
}*/
</style>
<body>
<center><h1>STUDENT DATABASE</h1>
<marquee direction="left">
Welcome to the student portal of DIST!!!
</marquee>
<img src="image.jpeg" width="800" height="450"><br>
<input type="button" value="insert student" onclick="window.location.href =
'studentdatabasehtml.html'" />
<input type="button" value="update student" onclick="window.location.href
='studentupdatehtml.html'"/>
<input type="button" value="delete student" onClick="window.location.href
='studentdeletehtml.html'"/>
<input type="button" value="view student" onClick="window.location.href
='studentview.php'"/>
</center>
</body>

DePaul Institute of Science & Technology(DIST) Page NO.


MCA 206 Software Development Lab-II(php)

</html>
**studentupdate.php**
<html><body>
<?php
$servername = "172.16.0.6";
$username = "mca20";
$password = "mca";
$databasename="mca20db";
// Create connection
$conn = new mysqli($servername, $username, $password,$databasename);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
$name=$_POST['name'];
$updatevalue=$_POST['updatevalue'];
$sql="update stud38 set age=$updatevalue where name='$name'";
//$sql = "INSERT INTO stud (sid,sname,age) VALUES (6, 'indhu', 25)";
if (mysqli_query($conn, $sql)) {
echo "<br>updated successfully";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
mysqli_close($conn);
?>
<br><br><input type="button" value="Back to home" onclick="window.location.href =
'studentmain.html'" />
</body>
</html>
**studentview.php**
<html>
<body>
<?php
$servername = "172.16.0.6";
$username = "mca20";
$password = "mca";
$databasename="mca20db";
// Create connection
$conn = new mysqli($servername, $username, $password,$databasename);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "<center>Connected successfully<br><br>----RECORDS----<br></center>";

DePaul Institute of Science & Technology(DIST) Page NO.


MCA 206 Software Development Lab-II(php)

$sql="select * from stud38 ";


$result=$conn->query($sql);
if ($result->num_rows>0) {
while($row=$result->fetch_assoc()){
echo "<br><center>name :".$row["name"]."<br>address :".$row["address"]."<br>age
:".$row["age"]."<br>course :".$row["course"]."</center><br>";
}
} else {
echo "0 rows";
}
mysqli_close($conn);
?>
<br><br><input type="button" value="Back to home" onclick="window.location.href =
'studentmain.html'" />
</body>
</html>

DePaul Institute of Science & Technology(DIST) Page NO.


OUTPUT
MCA 206 Software Development Lab-II(php)

PROGRAM NO: 24 DATE: 05-10-2021

AIM: Create a bookshop system using database.

PROGRAM:
**bookshopmain.html**
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<center><h1>BOOKSHOP SYSTEM</h1>
<marquee direction="left">
Welcome to the bookshop portal!!!
</marquee>
<img src="image1.jpeg" width="800" height="400"><br>
<a href="bookinserthtml.html">add book</a>
<a href="bookupdatehtml.html">update book</a>
<a href="bookdeletehtml.html">delete book</a>
<a href="bookview.php">view book</a>
</center>
</body>
</html>
**update.html**
<html>
<body><center>
<h1>Update Record</h1>
<img src="image1.jpeg" width="800" height="400"><br>
<form action="bookupdate.php" method=post>
<table>
<tr><td>Name :</td><td><input type=text name="name" /></td></tr>
<tr><td>stock :</td><td><input type=number name="stock" /></td></tr>
<tr><td></td><td><input type=submit name="submit" value="submit"/></td></tr>
</table>
</form></center>
</body>
</html>
**insert.html**
<html>
<body><center>
<h1>Insert Record</h1>
<img src="image1.jpeg" width="800" height="400"><br>
<form action="bookinsert.php" method=post>

DePaul Institute of Science & Technology(DIST) Page NO.


MCA 206 Software Development Lab-II(php)

<table>
<tr><td>name :</td><td><input type=text name="name"></td></tr>
<tr><td>price:</td><td><input type=number name="price"></td></tr>
<tr><td>stock :</td><td><input type=number name="stock" /></td></tr>
<tr><td></td><td><input type=submit name="submit" value="submit"/></td></tr>
</table>
</form></center>
</body>
</html>
**delete.html**
<html>
<body><center>
<h1>Delete Record</h1>
<img src="image1.jpeg" width="800" height="400"><br>
<form action="bookdelete.php" method=post>
<table><tr><td>Name to delete :</td><td><input type=text name="name"></td></tr>
<tr><td></td><td><input type=submit name="submit"
value="submit"/></td></tr></table>
</form>
</center>
</body>
</html>

DePaul Institute of Science & Technology(DIST) Page NO.


OUTPUT
MCA 206 Software Development Lab-II(php)

PROGRAM NO: 25 DATE: 05-10-2021

AIM: Perform arithmetic operation using javascript.

PROGRAM:
<html><body><script>
function arithmeticoperation(){
var a=parseInt(document.getElementById("a").value);
var b=parseInt(document.getElementById("b").value);
var linebreak="<br/>";
var c="<center/>";
document.write(c);
document.write("RESULTS");
document.write(linebreak);
document.write("----------");
document.write(linebreak);
document.write("sum=",a+b);
document.write(linebreak);
document.write("difference=",a-b);
document.write(linebreak);
document.write("product=",a*b);
document.write(linebreak);
document.write("quotient=",a/b);
document.write(linebreak);
document.write("reminder=",a%b);
}
</script><center><h1><u>Arithmetic Operations</u></h1>
<form name="f1"> <table>
<tr><td>Enter No.1:</td><td><input type="number" id="a" name="a"></td></tr>
<tr><td>Enter No.2:</td><td><input type="number" id="b" name="b"></td></tr>
<tr><td></td><td><input type="button" value="submit"
onclick="arithmeticoperation()"></td></tr>
</table></form>
</center></body></html>

DePaul Institute of Science & Technology(DIST) Page NO.


OUTPUT
MCA 206 Software Development Lab-II(php)

PROGRAM NO: 26 DATE: 06-10-2021

AIM: Program to find greater of 2 nos.

PROGRAM:
<html><body><script>
function greater(){
var a=parseInt(document.getElementById("a").value);
var b=parseInt(document.getElementById("b").value);
var c="<center/>";
document.write(c);
var linebreak="<br/>";
document.write("RESULTS");
document.write(linebreak);
document.write("----------");
document.write(linebreak);
if(a>b){
document.write(a,"\nis greater\n");
}
else if(b>a){
document.write(b,"\nis greater\n");
}
else{
document.write("\ntwo numbers are equal\n");
}}
</script><form name="f1">
<center> <h1><u>Greater of 2 nos</u></h1><table>
<tr><td>Enter No.1:</td><td><input type="number" id="a" name="a"></td></tr>
<tr><td>Enter No.2:</td><td><input type="number" id="b" name="b"></td></tr>
<tr><td></td><td><input type="button" value="submit" onclick="greater()">
</td></tr>
</table></center>
</form></body>
</html>

DePaul Institute of Science & Technology(DIST) Page NO.


OUTPUT
MCA 206 Software Development Lab-II(php)

PROGRAM NO: 27 DATE: 06-10-2021

AIM: Program to find reverse of a no.

PROGRAM:
<html>
<body>
<script>
function reverse(){
var n=parseInt(document.getElementById("n").value);
var c="<center/>";
var rev=0;
var res;
while(n>0)
{
res=n%10;
n=Math.floor(n/10);
rev=rev*10+res;
}
document.write(c);
var b="<br/>";
document.write("RESULT");
document.write(b);
document.write("----------");
document.write(b);
document.write("reverse is \n",rev);
}
</script><center><h1><u>Reverse of a no.</u></h1>
Enter the No:<input type="number" id="n" name="n"/><br><br>
<input type="button" value="submit" onclick="reverse()"/>
</center>
</body>
</html>

DePaul Institute of Science & Technology(DIST) Page NO.


OUTPUT
MCA 206 Software Development Lab-II(php)

PROGRAM NO: 28 DATE: 06-10-2021

AIM: Program to print prime nos upto a limit.

PROGRAM:
<html><body><script>
function prime(){
var n=parseInt(document.getElementById("n").value);
var i,j;
var c="<center/>";
document.write(c);
var b="<br/>";
document.write("RESULT");
document.write(b);
document.write("----------");
document.write(b);
document.write("the prime numbers :\n");
for(i=2;i<=n;i++) {
var f=0;
for(j=1;j<=i;j++) {
if(i%j==0) {
f++;
}}
if(f<=2)
document.write(i,"\n");
}}
</script><center><h1><u>Prime nos upto a limit</u></h1>
Enter the limit:<input type="number" id="n" name="n"/><br><br>
<input type="button" value="submit" onclick="prime()"/>
<center>
</body>
</html>

DePaul Institute of Science & Technology(DIST) Page NO.


OUTPUT
MCA 206 Software Development Lab-II(php)

PROGRAM NO: 29 DATE: 06-10-2021

AIM: Create a calculator using javascript.

PROGRAM:
<html> <head></head>
<body><center> <h2>Calculator</h2> <br>
<form Name="calc"><table border=2><tr>
<td colspan=4><input type=text Name="display"></td>
</tr><tr>
<td><input type=button value="0" OnClick="calc.display.value+='0'"></td>
<td><input type=button value="1" OnClick="calc.display.value+='1'"></td>
<td><input type=button value="2" OnClick="calc.display.value+='2'"></td>
<td><input type=button value="+" OnClick="calc.display.value+='+'"></td>
</tr><tr>
<td><input type=button value="3" OnClick="calc.display.value+='3'"></td>
<td><input type=button value="4" OnClick="calc.display.value+='4'"></td>
<td><input type=button value="5" OnClick="calc.display.value+='5'"></td>
<td><input type=button value="-" OnClick="calc.display.value+='-'"></td>
</tr><tr>
<td><input type=button value="6" OnClick="calc.display.value+='6'"></td>
<td><input type=button value="7" OnClick="calc.display.value+='7'"></td>
<td><input type=button value="8" OnClick="calc.display.value+='8'"></td>
<td><input type=button value="x" OnClick="calc.display.value+='*'"></td>
</tr><tr><td><input type=button value="9" OnClick="calc.display.value+='9'"></td>
<td><input type=button value="C" OnClick="calc.display.value=''"></td>
<td><input type=button value="="
OnClick="calc.display.value=eval(calc.display.value)"></td>
<td><input type=button value="/" OnClick="calc.display.value+='/'"></td>
</tr>
</table>
</form>
</center>
</body></html>

DePaul Institute of Science & Technology(DIST) Page NO.


OUTPUT
MCA 206 Software Development Lab-II(php)

PROGRAM NO: 30 DATE: 06-10-2021

AIM: Create a login page and validate it by including name ,password and

Confirm password.

PROGRAM:
<html>
<title>Login form and validation</title>
<head>
<script>
function validateform()
{
var name=document.form1.name.value;
var password=document.form1.pswd.value;
var confirm_password=document.form1.cpswd.value;
if (name=="" || password=="" || confirm_password=="")
{
alert("Fields can't be blank");
return false;
}
else if(password.length<6)
{
alert("Password must be at least 6 characters long...");
}
else if(password==confirm_password)
{
document.write("You are successfully logged in");
}
else
{
alert("password must be same!");
return false;
}
}

DePaul Institute of Science & Technology(DIST) Page NO.


</script>
</head>
<body>
<center>
<h2>Login Here....</h2><br><br>
<form name="form1" method="post" onsubmit="return validateform()" >
<table>
<tr>
<td><label>NAME</label></td><td>:<input type="text" name="email"></td>
</tr>
<tr></tr>
<tr>
<td><label>PASSWORD</label></td><td>:<input type="password"
name="pswd"></td>
</tr>
<tr></tr>
<tr></tr>
<tr>
<td><label>CONFIRM PASSWORD</label></td><td>:<input type="password"
name="cpswd"></td>
</tr>
<tr></tr>
<tr></tr><tr></tr>
<tr>
<td></td><td><input type="submit" value="Login"></td>
</tr>
</table></form></center>
</body>
</html>
MCA 206 Software Development Lab-II(php)

DePaul Institute of Science & Technology(DIST) Page NO.

You might also like