srinivasa Posted March 26, 2010 Report Share Posted March 26, 2010 Here i have attached two files names readnos.php and constuctor-calculator.php , read two nos from form inputs and do sum and diff , display...for setting initial values use constructor. readnos.php constuctor-calculator.php Quote Link to comment Share on other sites More sharing options...
srinivasa Posted March 26, 2010 Author Report Share Posted March 26, 2010 i hope u ll provide solution soon........ Quote Link to comment Share on other sites More sharing options...
krillz Posted March 26, 2010 Report Share Posted March 26, 2010 well you need to check whether the numbers were sent using POST or not, in the case where nothing was sent you will get errors as the POST variables are filled with nothing. one way would be checking whether anything was sent: { // Inside your class private $no1 = 0; private $no2 = 0; public function __construct(){ if( isset($_POST['no1'] ) && isset( $_POST['no2'] ) ) { $this->no1 = $_POST['no1']; $this->no2 = $_POST['no2']; } } public function add() { return $this->no1 + $this->no2; } public function subtract(){ return $this->no1 - $this->no2; } // your class ends } $test = new nameofclass(); echo $test->add(); echo $test->subtract(); of course you could add more stuff like sending them back to the form page if they didn't send anything and so on. Quote Link to comment Share on other sites More sharing options...
srinivasa Posted March 26, 2010 Author Report Share Posted March 26, 2010 am very grateful to you, given solution is perfectly alright. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.