<html>
<head><title>PHP calculator</title></head>
<body>
<?php
$var1 =$_POST['num1'];
$var2 =$_POST['num2'];
$equal = "";
$submitAdd =$_POST['submitAdd'];
$submitSub =$_POST['submitSub'];
$submitMul =$_POST['submitMul'];
$submitDiv =$_POST['submitDiv'];
if($submitAdd!=""){
$equal =$var1+$var2;
$operation = "+";
}
else if($submitSub!=""){
$equal =$var1-$var2;
$operation = "-";
}
else if($submitMul!=""){
$equal =$var1*$var2;
$operation = "*";
}
else if($submitDiv!=""){
$equal =$var1/$var2;
$operation = "/";
}
?>
<form name="form1" action="" method="post">
<p>CALCULATOR</p>
<p>
<input type="text" name="num1" size="1" value="<?php if($var1){ echo $var1;}?>"/>
<input type="text" name="num2" size="1" value="<?php if($var2){ echo $var2;}?>"/>
<input type="submit" name="submitAdd" id="button" value="add"/>
<input type="submit" name="submitSub" id="button" value="sub"/>
<input type="submit" name="submitMul" id="button" value="mul"/>
<input type="submit" name="submitDiv" id="button" value="div"/>
</p>
</form>
<?php
if($equal != "") echo "$var1 $operation $var2 = $equal";
?>
</body>
</html>
<head><title>PHP calculator</title></head>
<body>
<?php
$var1 =$_POST['num1'];
$var2 =$_POST['num2'];
$equal = "";
$submitAdd =$_POST['submitAdd'];
$submitSub =$_POST['submitSub'];
$submitMul =$_POST['submitMul'];
$submitDiv =$_POST['submitDiv'];
if($submitAdd!=""){
$equal =$var1+$var2;
$operation = "+";
}
else if($submitSub!=""){
$equal =$var1-$var2;
$operation = "-";
}
else if($submitMul!=""){
$equal =$var1*$var2;
$operation = "*";
}
else if($submitDiv!=""){
$equal =$var1/$var2;
$operation = "/";
}
?>
<form name="form1" action="" method="post">
<p>CALCULATOR</p>
<p>
<input type="text" name="num1" size="1" value="<?php if($var1){ echo $var1;}?>"/>
<input type="text" name="num2" size="1" value="<?php if($var2){ echo $var2;}?>"/>
<input type="submit" name="submitAdd" id="button" value="add"/>
<input type="submit" name="submitSub" id="button" value="sub"/>
<input type="submit" name="submitMul" id="button" value="mul"/>
<input type="submit" name="submitDiv" id="button" value="div"/>
</p>
</form>
<?php
if($equal != "") echo "$var1 $operation $var2 = $equal";
?>
</body>
</html>
No comments:
Post a Comment