Вы находитесь на странице: 1из 26

Name: Sinnarkar Krishna B. Roll no: 4353 TY.

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'];

if((!empty($no1)) && (!empty($no2)))


{
switch($cal)
{
case 1:$add=$no1+$no2;
echo "<h1>Addition=".$add."</h1>";
break;

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

if($_REQUEST['name']=="cdj" && $_REQUEST['pwd']=="123")


{
?>
<html>
<body>
<h1> <u><center>Enter Your Details</center></u> </h1>
<form action="c.php" method=get>
<input type="hidden" name="etime" value="<?php echo $t?>">
<h2> Enter Name : <input type="text" name="uname"> </h2><br>
<h2> Enter City : <input type="text" name="city"> </h2><br>
<h2> Enter Phone No : <input type="text" name="pno"> </h2><br>
<input type=submit name=submit value=DISPLAY>
</form>
</body>
</html>
<?php
}
else echo "<center><h1>Invalid Username Or Password</h1></center>"
?>

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)

3] Write a PHP Script to display Server information in table format (Use


$_SERVER).

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

4] Create a XML file which gives details of books available in “ABC


Bookstore” from following categories
1) Technical
2) Cooking
3) YOGA

<?xml version='1.0' ?>


<ABC_Bookstore>
<books category="technical">
<book_no>1</book_no>
<book_name>Computer Concepts</book_name>
<author_name>Rock</author_name>
<price>100</price>
<year>1990</year>
</books>
<books category="Cooking">
<book_no>2</book_no>
<book_name>The Joy Of Cooking</book_name>
<author_name>Satyam</author_name>
<price>200</price>
<year>1950</year>
</books>
<books category="YOGA">
<book_no>3</book_no>
<book_name>Application in Yoga</book_name>
<author_name>Gharote</author_name>
<price>150</price>
<year>2016</year>
</books>
</ABC_Bookstore>

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

<?xml version='1.0' encoding ='UTF-8' ?>


<bookstore>
<books category="technical">
<book_no>1</book_no>
<book_name>Java</book_name>
<author_name>Dack</author_name>
<price>100</price>
<year>1990</year>
</books>
<books category="Cooking">
<book_no>2</book_no>
<book_name>Cook </book_name>
<author_name>Aman</author_name>
<price>200</price>
<year>1950</year>
</books>
<books category="YOGA">
<book_no>3</book_no>
<book_name>DailyYoga</book_name>
<author_name>Finch</author_name>
<price>150</price>
<year>2016</year>
</books>
</bookstore>

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)

6] Write PHP script to create a CD catalog using XML file.

a.xml

<?xml version='1.0' encoding='UTF-8' ?>


<CD>
<cd type='music'>
<name>silent_songs</name>
<launch-date>5-6-2014</launch-date>
<composer>A-R-Rehman</composer>
</cd>

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

7] Write a PHP program to implement Create, Read, Update and Display


operations on Teacher table with attributes(tid, tname, address, subject). (Use
Radio Buttons)

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>

b.html // Create Table

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

$q2=mysql_query("insert into Emp values($a_no,'$a_name','$d_join',$a_sal,'$a_add')");


echo "<center><b><h2> Values Inserted Successfully.....!!!</h2><b></center>";
?>

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:

Вам также может понравиться