Hi Sandeep,
Try the below code:
<?php
class Util{
var $ipt1;
var $ipt2;
function setIpt1($data) {
$this->ipt1 = $data;
}
function setIpt2($data) {
$this->ipt2 = $data;
}
function __construct($post) {
$this->ipt1 = $post['ipt1'];
$this->ipt2 = $post['ipt2'];
}
function sum() {
return $this->ipt1 + $this->ipt2;
}
function diff() {
return $this->ipt1 - $this->ipt2;
}
}
if(isset($_POST['send'])) {
$util = new Util($_POST);
}
?>
<html>
<head>
<title>1. & 2. Class having ... </title>
</head>
<body>
<form action="" method="post">
Input 1:
<input type="text" name="ipt1" /><br />
Input 2:
<input type="text" name="ipt2" /><br />
<input type="submit" name="send" value="send" />
</form>
<?php
if(isset($util)) {
echo "<strong>Sum</strong>: ".$util->sum() . "<br />";
echo "<strong>Diff</strong>: ".$util->diff() . "<br />";
}
?>
</body>
</html>
Thanks
Sep 16, 2010