Академический Документы
Профессиональный Документы
Культура Документы
BBA(CA)
1] Write a PHP program to create a simple calculator that can accept two
numbers and perform operations like add, subtract, multiplication and divide.
(using Self Processing form)
<html>
<body>
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="POST">
<table>
<tr>
<td><h3>Enter first no :</td><td><input type="text" name="no1" ></h3></td>
</tr>
<tr>
<td><h3>Enter second no :</td><td><input type="text" name="no2"></h3></td>
</tr>
<tr>
<td><b>Select Operation which u have to perform :</b></td>
<td><select name=cal>
<option value="1">Addition</option>
<option value="2">Substraction</option>
<option value="3">Multiplication</option>
<option value="4">Division</option>
</select></td>
</tr>
<tr>
<td></td><td><input type=submit name=submit value=Calculate></td>
</tr>
</table>
</form>
</body>
</html>
<?php
if(isset($_POST['submit']))
{
$no1=$_POST['no1'];
$no2=$_POST['no2'];
$cal=$_POST['cal'];
case 2:$sub=$no1-$no2;
echo "<h1>Subtraction=".$sub."</h1>";
break;
case 3:$mult=$no1*$no2;
echo "<h1>Multiplication=".$mult."</h1>";
break;
case 4:$div=$no1/$no2;
echo "<h1>Division=".$div."</h1>";
break;
}
}
else echo "<b>Please enter both 2 nos</b>";
}
else
die("not able to acccess");
?>
Output:
Name: Sinnarkar Krishna B. Roll no: 4353 TY.BBA(CA)
2] Create a login form with a username and password. Once the user logs in,
the second form should be displayed to accept user details (name, city,
phoneno). If the user doesn’t enter information within a specified time limit,
expire his session and give a warning otherwise Display Details($_SESSION).
a.html
<html>
<body>
<form action="b.php" method="post">
<center>
<h2> Enter Username : <input type="text" name="name"> </h2>
<h2> Enter Password : <input type="text" name="pwd"> </h2>
<input type="submit" value="Login">
</center>
</form>
</body>
</html>
b.php
<?php
session_start();
$t=date("1,d-m-y h:i:s",time()+20);
c.php
<?php
session_start();
$t=$_REQUEST['etime'];
$exp=date("1,d-m-y h:i:s",time());
if($t<$exp)
echo "<center><h1>Page Time Expired</h1></center>";
else
{
echo "<center><h2>Name : ".$_REQUEST['uname']."</h2></center>";
echo "<center><h2>City : ".$_REQUEST['city']."</h2></center>";
echo "<center><h2>Phone NO : ".$_REQUEST['pno']."</h2></center>";
session_destroy();
}
?>
Output:
Name: Sinnarkar Krishna B. Roll no: 4353 TY.BBA(CA)
<?php
echo"<table border=1>";
foreach($_SERVER as $k=>$v)
{
echo"<tr><td>".$k."</td><td>".$v."</td></tr>";
}
echo"</table>";
?>
Output:
Name: Sinnarkar Krishna B. Roll no: 4353 TY.BBA(CA)
Output:
Name: Sinnarkar Krishna B. Roll no: 4353 TY.BBA(CA)
5] Create an application that reads “Book.xml” file into simple XML object.
Display attributes and elements(Hint: use simple_xml_load_file() function).
a.xml
b.php
<?php
$xml=simplexml_load_file("a.xml") or die("eror:cannot create object");
var_dump($xml);
?>
Output:
Name: Sinnarkar Krishna B. Roll no: 4353 TY.BBA(CA)
a.xml
<cd type='music'>
<name>Hip-Hop</name>
<launch-date>4-8-2011</launch-date>
<composer>Yo-Yo-Honey singh</composer>
</cd>
<cd type='music'>
<name>love track</name>
<launch-date>6-9-2000</launch-date>
<composer>Arjit Singh</composer>
</cd>
</CD>
Output:
Name: Sinnarkar Krishna B. Roll no: 4353 TY.BBA(CA)
a.html
<html>
<body>
<form action="b.php" method="get">
<center> <h2> Enployee Details :</h2> <br>
<table>
<tr>
<td><input type="radio" name="r" value="1"></td>
<td><b>Create Employee Table:</b></td>
</tr>
<tr>
<td><input type="radio" name="r" value="2"></td>
<td><b> Read/Insert Values :</b></td>
</tr>
<tr>
<td><input type="radio" name="r" value="3"></td>
<td><b>Update Values :</b></td>
</tr>
<tr>
<td><input type="radio" name="r" value="4"></td>
<td><b>Display :</b></td>
</tr>
</table>
<br> <input type="submit" value="Submit" name="submit">
</center>
</form>
</body>
</html>
<?php
$r=$_GET['r'];
$con = mysql_connect("localhost","root","");
$d = mysql_select_db("Krishna",$con);
if($r==1)
{
$q=mysql_query("create table Emp(empno int,ename varchar(10),date_of_join
date,salary int,address varchar(20))");
echo "<center><b><h2> Table Created Successfully.....!!!</h2><b></center>";
}
else if($r==2)
{
header("location:insert.html");
}
else if($r==3)
{
header("location:update.html");
}
else if($r==4)
{
$q4=mysql_query("select *from Emp");
echo "<center>";
echo "<table border=1 width=30% height=20%>";
echo "<h2><tr><td><b> Emp No </b></td><td> <b>Employee Name<b> </td><td> <b>Date
Of Joining <b></td><td> <b>Salary <b></td><td> <b>Address<b> </td></tr></h2>";
while($row=mysql_fetch_array($q4))
{
echo
"<tr><td>".$row[0]."</td><td>".$row[1]."</td><td>".$row[2]."</td><td>".$row[3]."</td><td>"
.$row[4]."</td></tr>";
}
echo "</table>";
echo "</center>";
}
?>
Insert.html
<html>
<body>
<form action="insert.php" method="get">
<center> <h2>Enter Enployee Details :</h2> <br>
<table>
<tr>
<td>Enter Employee no :</td>
<td><input type="text" name="a_no"> </td>
</tr>
<tr>
<td>Enter Employee name :</td>
<td><input type="text" name="a_name"></td>
</tr>
<tr>
<td>Enter Date Of Join :</td>
<td><input type="text" name="d_join"></td>
</tr>
<tr>
<td>Enter Salary :</td><td><input type="text" name="a_sal"></td>
</tr>
<tr>
<td>Enter Address :</td>
<td><input type="text" name="a_add"></td>
</tr>
<tr>
<td><input type="submit" value="Show" name="submit"></td>
</tr>
</table>
</center>
</form>
</body>
</html>
Insert.php
<?php
$a_no=$_GET['a_no'];
$a_name=$_GET['a_name'];
$d_join=$_GET['d_join'];
$a_sal=$_GET['a_sal'];
$a_add=$_GET['a_add'];
$con = mysql_connect("localhost","root","");
$d = mysql_select_db("Krishna",$con);
Update.html
<html>
<body>
<form action="update.php" method="get">
<center> <h2>Update Enployee Details :</h2> <br>
<table>
<tr>
<td> Employee no :</td>
<td><input type="text" name="a_no" > </td>
</tr>
<tr>
<td> Employee name :</td>
<td><input type="text" name="a_name" ></td>
</tr>
<tr>
<td> Date Of Join :</td>
<td><input type="text" name="d_join" ></td>
</tr>
<tr>
<td> Salary :</td>
<td><input type="text" name="a_sal" ></td>
</tr>
<tr>
<td> Address :</td>
<td><input type="text" name="a_add" ></td>
</tr>
<tr>
<td><input type="submit" value="Show" name="submit"></td>
</tr>
</table>
</center>
</form>
</body>
</html>
Update.php
<?php
$a_no=$_GET['a_no'];
$a_name=$_GET['a_name'];
$d_join=$_GET['d_join'];
$a_sal=$_GET['a_sal'];
$a_add=$_GET['a_add'];
$con = mysql_connect("localhost","root","");
$d = mysql_select_db("Krishna",$con);
$r=mysql_query("update Emp set
empno=$a_no,ename='$a_name',date_of_join='$d_join',salary='$a_sal',address='$a_add' where
empno=$a_no");
echo"Record Updated"
?>
Output:
Name: Sinnarkar Krishna B. Roll no: 4353 TY.BBA(CA)
8] Write a simple PHP program which implements Ajax for addition of two
numbers.
Ajax.html
<html>
<head>
<script type="text/javascript">
function Addition()
{
var ob=false;
ob=new XMLHttpRequest();
var no1=document.getElementById("no1").value;
var no2=document.getElementById("no2").value;
ob.open("GET","ajax.php?num1="+no1+"&num2="+no2);
ob.send();
ob.onreadystatechange=function()
{
if(ob.readyState==4 && ob.status==200)
document.getElementById("add").innerHTML=ob.responseText;
}
</script>
</head>
<body>
Enter first no :<input type=text name=no1 id="no1"><br>
Enter second no :<input type=text name=no2 id="no2"><br>
<input type=button name=submit value=add onClick="Addition()"><br>
<span id="add"></span>
</body>
</html>
Ajax.php
<?php
$n1=$_GET['num1'];
$n2=$_GET['num2'];
if((!empty($n1)) && (!empty($n2)))
{
$add=$n1+$n2;
echo "Addition = ".$add;
}
else "enter both nos";
?>
Output:
Name: Sinnarkar Krishna B. Roll no: 4353 TY.BBA(CA)
9] Write a script to keep track of number of times the web page has been
accessed (use $_COOKIE).
<?php
if(isset($_COOKIE['cnt']))
{
$x=$_COOKIE['cnt'];
$x=$x+1;
setcookie('cnt',$x);
echo"You accessed this page ".$_COOKIE['cnt']." times";
}
else
{
setcookie('cnt',1);
echo "you accessed this page 1st time";
}
?>
Output:
Name: Sinnarkar Krishna B. Roll no: 4353 TY.BBA(CA)
10] Write class declarations and member function definitions for following
employee(code, name, designation). Design derived classes as
emp_account(account_no, joining_date) from employee and
emp_sal(basic_pay, earnings, deduction) from emp_account.
Write a PHP Script to create 5 objects (pass details using parameterized
constructor) and Display details of Employees who having Maximum and
Minimum Salary.
<?php
class Employee
{
public $eid,$ename,$edesg;
function __construct($a,$b,$c)
{
$this->eid=$a;
$this->ename=$b;
$this->edesg=$c;
}
public function getdata()
{
return $this->sal;
}
public function display()
{
echo $this->eid."<br>";
echo $this->ename."<br>";
echo $this->edesg."<br>";
}
}
class Emp_account extends Employee
{
public $ac_no,$jdate;
public static $total1=0;
function __construct($a,$b,$c,$d,$e)
{
parent::__construct($a,$b,$c);
$this->ac_no=$d;
$this->jdate=$e;
}
}
class Emp_sal extends Emp_account
{
public $b_pay,$er,$dud;
function __construct($a,$b,$c,$d,$e,$f,$g,$h)
{
parent::__construct($a,$b,$c,$d,$e);
$this->b_pay=$f;
$this->er=$g;
$this->dud=$h;
}
public function max($ob)
{
$total=$this->b_pay+$this->er;
$total=$total-$this->dud;
if($total>self::$total1)
{
self::$total1=$total;
return $this;
}
else
{
return $ob;
}
}
public function min($ob)
{
$total=$this->b_pay+$this->er;
$total=$total-$this->dud;
if($total<self::$total1)
{
self::$total1=$total;
return $this;
}
else
{
return $ob;
}
}
public function display()
{
echo "<br> Employee Id : ".$this->eid;
echo "<br> Employee Name : ".$this->ename;
echo "<br> Employee Designation : ".$this->edesg;
}
}
$ob=new Emp_sal(0,"ABC","",0,"",0,0,0);
$temp=new Emp_sal(0,"ABC","",0,"",0,0,0);
$ob1=new Emp_sal(1,"Eminem","HOD",1234,"21/3/2015",28000,2000,500);
$ob=$ob1->max($ob);
$temp=$ob1->min($temp);
$ob2=new Emp_sal(2,"Smith","HOD",1234,"21/3/2015",48000,2000,500);
$ob=$ob2->max($ob);
$temp=$ob2->min($temp);
$ob3=new Emp_sal(3,"Rock","CEO",1234,"21/3/2015",58000,2000,500);
$ob=$ob3->max($ob);
$temp=$ob3->min($temp);
$ob4=new Emp_sal(4,"Satya","Manager",1234,"21/3/2015",8000,2000,500);
$ob=$ob4->max($ob);
$temp=$ob4->min($temp);
$ob5=new Emp_sal(5,"Om","HOD",1234,"21/3/2015",7000,2000,500);
$ob=$ob5->max($ob);
$temp=$ob5->min($temp);
echo "<h1>Maximum Salary Emp :</h1>";
$ob->display();
echo "<br><h1>Minimum Salary Emp: </h1>";
$temp->display();
?>
Output: