I have been trying to learn PHP for the past week now.
I have created a form which acts like a calculator in which two values are either added up, subtracted, multiplied or divided.
$cal = new calculator();
if(isset($_POST['submit']))
{
$result = $cal->getresult($_POST['n1'],$_POST['n2'],$_POST['op']);
}
if(isset($_POST['reset'])){
$result = false;
}
?>
<form method="post">
<table align="center">
<tr>
<td><b><?php echo $result; ?></b></td>
</tr>
<tr>
<td>Zahl 1 </td>
<td><input type="number" name="n1"></td>
</tr>
<tr>
<td>Zahl 2 </td>
<td><input type="number" name="n2"></td>
</tr>
<tr>
<td>Select Oprator</td>
<td><select name="op">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="submit" value="Berechnen"></td>
</tr>
<tr>
<td></td>
<td><input type="reset" name="reset" value="Reset"></td>
</tr>
</table>
</form>
Beforehand I define the calculator-class but it is not relevant for this question.
So what I want to do is when I click the
<td><input type="reset" name="reset" value="Reset"></td>
button i want the variable $result to be defined as empty, which I want to achieve by
if(isset($_POST['reset'])){
$result = false;
}
In effect, php should not show the result on top of the document, because
<tr>
<td><b><?php echo $result; ?></b></td>
</tr>
is empty?
Unfortunately, that doesn't happen. Does anyone know how to fix this?