You are on page 1of 6

<?

php
ini_set('display_errors',0);
if( isset( $_REQUEST['calculate'] ))
{
$operator=$_REQUEST['operator'];
if($operator=="+")
{
$add1 = $_REQUEST['fvalue'];
$add2 = $_REQUEST['lvalue'];
$res= $add1+$add2;
}
if($operator=="-")
{
$add1 = $_REQUEST['fvalue'];
$add2 = $_REQUEST['lvalue'];
$res= $add1-$add2;
}
if($operator=="*")
{
$add1 = $_REQUEST['fvalue'];
$add2 = $_REQUEST['lvalue'];
$res =$add1*$add2;
}
if($operator=="/")
{
$add1 = $_REQUEST['fvalue'];
$add2 = $_REQUEST['lvalue'];
$res= $add1/$add2;
}
if($_REQUEST['fvalue']==NULL && $_REQUEST['lvalue']==NULL)

{
echo "<script language=javascript> alert(\"Please Enter values.\");</script>";
}
else if($_REQUEST['fvalue']==NULL)
{
echo "<script language=javascript> alert(\"Please Enter First value.\");</script
>";
}
else if($_REQUEST['lvalue']==NULL)
{
echo "<script language=javascript> alert(\"Please Enter second value.\");</scrip
t>";
}
}
?>
<form>
<table style="border:groove #00FF99">
<tr>
<td style="background-color:aqua; color:red; font-family:'Times
New Roman'">Enter First Number</td>
<td colspan="1">

<input name="fvalue" type="text" style="color:red"/></td>


<tr>
<td style="color:burlywood; font-family:'Times New Roman'">Selec
t Operator</td>
<td>
<select name="operator" style="width: 63px">
<option>+</option>
<option>-</option>
<option>*</option>
<option>/</option>

</select></td>
</tr>
<tr>
<td style="background-color:aqua; color:red; font-family:'Times
New Roman'">Enter First Number</td>
<td class="auto-style5">
<input name="lvalue" type="text" style="color:red"/></td>

</tr>
<tr>
<td></td>
<td><input type="submit" name="calculate" value="Calculate" styl
e="color:wheat;background-color:rosybrown" /></td>

</tr>
<tr>
<td style="background-color:aqua;color:red">Output = </td>
<td style="color:darkblue"><?php echo $res;?></td>

</tr>
</table>
</form>

--------------------------------------------------------------------------calculator.php
<html>
<head>
<title>CALCULATOR USING PHP</title>
<style type="text/css">
/*ADDING BACKGROUNG COLOUR ANS SETT
INGS*/
body{
background-color: #d2b48c;
margin-left: 20%;
margin-right:20%;
border: 1px dotted gray;

font-family: sans-serif;
}
</style>
<head>
<body>
<center></br></br>
<form name="frm" action="form1.php" method="post">
Enter Value:
<input type="text" name="first" value= "<?php echo $_REQUEST['number'];
echo $_REQUEST['calculate'];echo $_REQUEST['result']; ?>"> </br></br>
</from>
<form name="frm" action="form1.php" method="post">
<input type="submit" name="number" value="1">
</from>
<form name="frm" action="form1.php" method="post">
<input type="submit" name="number" value="2">
</from>
<form name="frm" action="form1.php" method="post">
<input type="submit" name="number" value="3"></br></br>
</from>
<form name="frm" action="form1.php" method="post">
<input type="submit" name="number" value="4">
</from>
<form name="frm" action="form1.php" method="post">
<input type="submit" name="number" value="5">
</from>
<form name="frm" action="form1.php" method="post">
<input type="submit" name="number" value="6"></br></br>
</from>
<form name="frm" action="form1.php" method="post">
<input type="submit" name="number" value="7">
</from>
<form name="frm" action="form1.php" method="post">
<input type="submit" name="number" value="8">
</from>
<form name="frm" action="form1.php" method="post">
<input type="submit" name="number" value="9"></br></br>
</from>
<form name="frm" action="form1.php" method="post">
<input type="submit" name="calculate" value="+">
</from>
<form name="frm" action="form1.php" method="post">
<input type="submit" name="calculate" value="0">
</from>

<form name="frm" action="form1.php" method="post">


<input type="submit" name="calculate" value="*"></br></br>
</from>
<form name="frm" action="form1.php" method="post">
<input type="submit" name="calculate" value="/">
</from>
<form name="frm" action="form1.php" method="post">
<input type="submit" name="calculate" value="-"></br></br>
</form>
<form name="frm" action="form1.php" method="post">
<input type="submit" value="=" name="result">
</form>
</center>
</body>
</html>
form1.php

<html>
<head>
<title></title>
</head>
<body>
<?php
if(isset($_POST['result']))
{
include "at.php";
$oper=$_POST['calculate'];
if($_oper == '+')
{
echo "+";
$oper='+';
$result=$_POST['number']+10;
echo $result;
}
else if($oper == '-')
{
echo "-";
$oper='-';
$result=$_POST['number']-10;
echo $result;
}
else if($_POST['calculate'] == '/' )
{
echo "/";
$oper='/';
$result=$_POST['number']/10;

echo $result;
}
else
{
echo "*";
$oper='*';
$result=$_POST['number']*10;
echo $result;
}
}
if(isset($_POST['number']))
{
include "at.php";
$var=$_POST['number'];
echo "</br>";
echo $var;
echo "Enter the operator";
}
if(isset($_POST['calculate']))
{
include "at.php";
$oper=$_POST['calculate'];
echo $_POST['calculate'];
echo "</br>";
}
?>
</body>
</html>

You might also like