im sry if this question has been asked b4
this is my code:
index.php:
<?php
include_once 'includes/calc.inc.php';
?>
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<form action="" method="post">
<input type="text" name="num1" placeholder="Number 1...">
<input type="text" name="num2" placeholder="Number 2...">
<select name="oper">
<option type="text" value="none">None</option>
<option type="text" value="add">Add</option>
<option type="text" value="sub">Subtract</option>
<option type="text" value="mul">Multiply</option>
<option type="text" value="div">Divide</option>
</select>
<button type="submit" name="submit">Submit</button>
</form>
<?php
$number1 = $_POST['num1'];
$number2 = $_POST['num2'];
$operator = $_POST['oper'];
$calc = new Calculator;
$calc->Calc($number1, $number2, $operator);
?>
</body>
</html>
calc.inc.php:
<?php
class Calculator {
public $num1;
public $num2;
public $oper;
public $result;
public function Calc($num1in, $num2in, $operin) {
$this->num1 = $num1in;
$this->num2 = $num2in;
$this->oper = $operin;
switch ($this->oper) {
case 'none':
$this->result = "Please select method of calculating";
break;
case 'add':
$this->result = $this->num1 + $this->num2;
break;
case 'sub':
$this->result = $this->num1 - $this->num2;
break;
case 'mul':
$this->result = $this->num1 * $this->num2;
break;
case 'div':
$this->result = $this->num1 / $this->num2;
break;
default:
echo "error";
break;
return $this->result;
}
}
}
i saw a calculator on github and compared and both code looked about the same. it might be the return statement at the end of the code in calc.inc.php but idk. i just finished learning php and this is my first project all help appreciated 🙂
>Solution :
You’re not displaying the result. After the line $calc->Calc($number1, $number2, $operator); you should add something like:`
print 'Result = '.$calc->return;