Forum : php oop assingment
Brief description  about Online courses   join in Online courses
View sandeep kumar mahala 's Profile

php oop assingment

Create a class having
a) 1 method of getting two input. For getting input from user use text box.

can anyone tell me how to use text field for input in php class.
Asked by sandeep kumar mahala | Sep 7, 2010 |  Reply now
Replies (1)
View teacher siliconindia 's Profile
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. &amp; 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