Click here to Skip to main content
15,123,118 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How can I Get Value Of Addition


HTML
<pre>
<HTML>
<HEAD>
 <TITLE>New Document</TITLE>
</HEAD>
<BODY>
<form action="calc.php"method="POST">
  <input type="text" name="num1" >
  <input type="text" name="num2" >
   
  <button type="_submit_">Calculate</button>
</form>
</BODY>
</HTML>


What I have tried:

PHP
<pre>
<?php
include 'calc.inc.php';
$num1 = $_POST['num1'];
$num2 = $_POST['num2'];
 $calculator = new Calc($num1,$num2);
echo $calculator->calcMethod();

?>



PHP
<?php
  class Calc {
  public $num1;
  public $num2;
  public $cal;
  public function _construct($num1, $num2){ 
    $this->num1 = $num1;
    $this->num2 = $num2;
 
  }
  public function calcMethod(){
  
    $result = $this->num1 + $this->num2;
    echo $result;
  }

  }
?>
Posted
Updated 25-May-21 4:59am
Comments
Richard MacCutchan 24-May-21 7:07am
   
What is the problem?
Member 15213574 24-May-21 11:42am
   
please watch my PHP code It's not Correct . I Need Addition Value on this Way
Richard MacCutchan 24-May-21 12:00pm
   
What do you mean, "It's not Correct"? Please provide proper details of your problem.
Member 15213574 24-May-21 12:10pm
   


 <title>New Document



  
  
   
  Calculate



<pre>
calcMethod();

?>
num1 = $num1;
    $this->num2 = $num2;
 
  }
  public function calcMethod(){
  
    $result = $this->num1 + $this->num2;
    echo $result;
  }

  }
?>
Richard MacCutchan 24-May-21 12:20pm
   
Where is the code that handles the button click?

1 solution

Problems all over - maybe, since your descriptions are rather poor.

So I'll make some guesses.

I'm guessing function calcMethod() (in class calc) is you intended include file (you didn't give us the name). Try return $result; instead of echo $result;.

Is the name of the file you wish to include really calc.inc.php and not calc.inc or calc.php ? Just check to be sure.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900